in reply to Piping output into a log file
To be honest, it's not entirely clear to me what you're trying to do. At the very least, you're missing some double-quotes. What are you going to do with the $cmd variable? Send it to system?
system($cmd);
That would work better with the ">>" outside of the command. Here we're just worried about a bit of shell scripting:
Thus, in your perl code, you want a command something like this:/usr/bin/rsh somehost -l someuser "ls -l" >> /tmp/someFile
Or, if you want to be really sneaky/smart, you want to open the file at the beginning, ...my $cmd = qq[$rsh $host -l $id "$command" >> $someFile]; system($cmd);
and put all your output to it.my $output = IO::File->new("|tee $someFile"); local *STDOUT; open STDOUT, '>&', $output;
Note also how I've changed your quotes - escaping quotes is annoying, so by using one of the other quote operators, we're freed from continuous hitting of the backslash key which was annoying when I worked on OS/2, and is doubly annoying now that I work on Linux/Unix (since I'm out of the habit) :-)my $cmd = qq[$rsh $host -l $id "$command"]; system($cmd);
Finally, one more change:
Now that I've removed all your special characters (the >>), we don't need the shell anymore. This will make building up $command (which is still going to use the shell on the remote machine) much easier as there will be significantly less to interpolate. One less layer of escaping. This may mean changing your $command to remove extra backslashes, but you'll thank me when you have to come back and re-read it later :-)my @cmd = ($rsh, $host, '-l', $id, $command); print "Executing: ", join(' ', @cmd), "\n"; system(@cmd)
Update: changed close STDOUT to local *STDOUT. Works better now.
|
|---|