Hello again,
You guys were such a great help on my last problem that I've returned with a new one. I'm new to Perl and am trying my hand at a concatenation script. It's a bit clunky and I want to add some features but am not sure how. Any help or suggestions is most welcome and I thank you in advance.

My objective here is to:

1) Clean this script up

2) SCP errors not being handled correctly

3) Do something with the "Number of days to go back" entry so I can just put in 1 number for a week, month, etc.

4) create a tar file with a date stamp on the name that holds all the files being concatenated and the resulting file from the process, then move the tar file to an archive directory.

Here's the script:

# THIS SCRIPT CONCATENATES DATA FOR 1 WEEK OF RELIANT TRUST DATA AND S +ENDS TO NDM # $MT='my.email.com'; # Mail Alias used for sending emails $ASL='app-server'; @BFL=('name1.log','name2.log'); # START TIME AND DATE VARIABLES # $now = time(); $yesterday = $now - 3600*24; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($yes +terday); $yestermday=sprintf("%02d", $mday); $yesterwday=$wday; $lf="$0.$yesterwday.log"; open(LF,">$lf"); $year += 1900; $mon++; $mon = sprintf("%02d", $mon); $mday = sprintf("%02d", $mday); # # END TIME AND DATE VARIABLES # Saturday only ($wday=Friday), push concatenation of 7 days data if ($yesterwday == 5) { # compute last 7 days of file names # cat the files foreach $f (@BFL) { $catfile = "$f\.$year$mon$yestermday"; unlink $catfile; # in case we run 2x in one day foreach $i (5,6,7,8) { for $dd (7,6,5,4,3,2,1) { # Number of days to go bac +k for process $then = $now - $dd*3600*24; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) += localtime($then); $mday = sprintf("%02d", $mday); $year += 1900; $mon++; $mon = sprintf("%02d", $mon); $fileext = "$f\.myservername$i\.$year$mon$mday"; $command = "cat $fileext.$ASL$i >> $catfile 2>/dev/nul +l"; if ($debug) { print "WOULD $command\n"; } else { $output = `$command`; } $exit_value = $? >> 8; if ($exit_value == 2) { print LF "Assuming it's not there: $fileext.$ASL$i +\n"; } elsif ($exit_value) { print LF "Trouble with command: $command\n"; print LF "$output\n"; $errs++; } else { print LF "OK: $command\n"; } } } } # the cat-ed file is produced: scp it $filetoput = "/home/echxfr/$catfile"; @cmd = ( '/usr/bin/scp', "$catfile", "cduser\@ndm:$filetoput", ); $rv = system(@cmd); if ($rv == -1) { print("Unable to execute scp: $!\n"); } elsif ($rv & 127) { printf("scp to died with signal %d\n", ($rv & 127)); } elsif ($rv >> 8) { printf("scp exited with error %d\n", ($rv >> 8)); } else { print("scp was successful\n"); } $fname = "$catfile"; if (-z $fname ) { `/bin/mailx -s "ERROR: Reliant SCP Log file $fname sent to ndm + is empty" $MT`; } }


In reply to Help with Concatenates script by wskibum

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.