Movatterモバイル変換


[0]ホーム

URL:


CFEngine documentation homepage

readfile

Suggest changes
Table of contents

Prototype:readfile(filename, optional_maxbytes)

Return type:string

Description:Returns the firstmaxbytes bytes from filefilename.maxbytes is optional, if specified, only the firstmaxbytes bytes are read fromfilename.Whenmaxbytes is0,inf or not specified, the whole file will be read (but seeNotes below).

Arguments:

  • filename:string - File name - in the range:"?(/.*)
  • optional_maxbytes:int - Maximum number of bytes to read - in the range:0,99999999999

Example:

Prepare:

code
echo alpha > /tmp/cfe_hostlistecho beta >> /tmp/cfe_hostlistecho gamma >> /tmp/cfe_hostlist

Run:

code
bodycommoncontrol{bundlesequence=>{"example"};}bundleagentexample{vars:"xxx"string=>readfile("/tmp/cfe_hostlist","5");reports:"first 5 characters of /tmp/cfe_hostlist:$(xxx)";}

Output:

code
R: first 5 characters of /tmp/cfe_hostlist: alpha

Notes:

  • On Windows, the file will be read in text mode, which means thatCRLF line endings will be converted to LF line endings in theresulting variable. This can make the variable length shorter than thesize of the file being read.

History:

  • Warnings about the size limit and the special0 value were introduced in 3.6.0
  • 4095 bytes limitation removed in 3.6.3

Still need help?

Chat Ask a question on Github Mailing list
Version 
master3.24 (LTS)3.21 (LTS)view all versions

[8]ページ先頭

©2009-2025 Movatter.jp