I've got two scripts. One that will back up crontabs on remote machines, one that will backup directories. The crontab one simply ssh'es to the target, lists the crontab, and prints out. I use a simple
open ( CRON, "ssh host crontab -l" ) || die $!;
while ( <CRON> ) {
print $_;
}
It works just fine.
Doing something similar for rsync:
open ( RSYNC, "rsync -az -e \"ssh -o BatchMode=yes\" --delete-after ho
+st:/path/to/dir /path/to/backup |" );
while ( <RSYNC> ) {
print "output: $_";
}
The rsync command will only print out something when it doesn't work properly. In this case, I actually store it and do something w/ it later. What I've found though, is that when I run the script, it is spitting the output out on the terminal... not being captured in the file handle. I assume ssh is printing to stdout and rsync to something else, but I thought Perl would capture any output, if I open a command as a file handle.
Before anyone asks, I'm not using the Perl modules as I've had a very hard time w/ them, due to different SSH versions on my network. That is beyond my control, so I'm adapting. The above works much better, sans the output issue.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.