Let me make this clear this script below is working fine. the only thing is instead of getting dir and hostnames from the script itself i need to read from text file. testfile
mshostname1
"/etc/init.d/"
"/var/logs/"
mshostname2"
"/whatever/"
"/more/"
This is the working script
#!/usr/bin/perl my $server = 'nfserver'; my $scp = '/usr/bin/scp'; my $time = localtime; my @mshost1 = ( "msname1", "/local/home/gloob", "/var/spool/cron/crontabs", "/local/home/admin/service.etc" ); my @mshost2 = ( "msname2", "/local/p0/home/gob", "/var/spool/cron/crontabs", "/local/p0/home/admin/service.etc" ); sub backup { my $client = shift; if ($client eq $client) { print "About to tar and scp the following folders: @dir\n\n"; system("ssh", $client, "tar -cvvf $client\.tar.gz @dir"); print("===============================\n"); system("ssh", $client, "scp $client\.tar.gz root\@$server:/export/prod +ucts/backup/"); } else { print "could not backup $client\n"; } } sub get_dir_msd { $client = shift(@mshost1); @dir = @mshost1; print "@dir\n"; print "$client\n"; backup($client); } sub get_dir_msd2 { $client = shift(@mshost2); @dir = @mshost2; print "@dir\n"; print "$client\n"; backup($client); } get_dir_msd("mshost2"); get_dir_msd2("mshost1");

In reply to Re^4: Read File into array and split by tokyobuddha
in thread Read File into array and split by tokyobuddha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.