NAME
Rex::Commands::File
DESCRIPTION
With this module you can manipulate files.
SYNOPSIS
task "read-passwd", "server01", sub {
my $fh = file_read "/etc/passwd";
say $fh->read_all;
$fh->close;
};
task "write-passwd", "server01", sub {
my $fh = file_write "/etc/passwd";
$fh->write("root:*:0:0:root user:/root:/bin/sh\n");
$fh->close;
};
EXPORTED FUNCTIONS
- file_write($file_name)
-
This function opens a file for writing (it will truncate the file if it already exists). It returns a Rex::FS::File object on success.
On failure it will die.
my $fh; eval { $fh = file_write("/etc/groups"); }; # catch an error if($@) { print "An error occured. $@.\n"; exit; } # work with the filehandle $fh->write("..."); $fh->close;
- file_append($file_name)
- file_read($file_name)
-
This function opens a file for reading. It returns a Rex::FS::File object on success.
On failure it will die.
my $fh; eval { $fh = read("/etc/groups"); }; # catch an error if($@) { print "An error occured. $@.\n"; exit; } # work with the filehandle my $content = $fh->read_all; $fh->close;