You could just use scp. scp is way better than sftp for scripting, IMO. And also, for sysadmin type tasks, I would rather use Perl as glue, than try to reinvent tools with it just to do it in Pure Perl. Just too... religious, for me.
I use public/private keys for authentication in this case, because not only is it (only slighter) safer than putting the password in the script, but it removes the need to interact with scp in order to transfer files.
perl -e '@hosts = ( map { $_ . q[.example.com] } qw/ foo bar www / );
+system( q[scp], q[-r], @ARGV, sprintf(q[%s:remotedir], $_) ) foreach
+@hosts;' /tmp/foo
Here is another version using ssh and rsync, so as to only send the parts that changed, and ignores .CVS files:
perl -e '@hosts = ( map { $_ . q[.example.com] } qw/ foo bar www / );
+system( q[rsync], q[-rcC], q[-e], q[ssh], @ARGV, sprintf(q[%s:remoted
+ir], $_) ) foreach @hosts;' /tmp/foo
Of course, if the usernames on the aren't the same, you have to add that also.
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.