wskibum has asked for the wisdom of the Perl Monks concerning the following question:
# 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`; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Concatenates script
by moritz (Cardinal) on Apr 03, 2008 at 17:18 UTC | |
by wskibum (Initiate) on Apr 03, 2008 at 17:59 UTC | |
|
Re: Help with Concatenates script
by leocharre (Priest) on Apr 03, 2008 at 21:48 UTC | |
|
Re: Help with Concatenates script
by apl (Monsignor) on Apr 03, 2008 at 17:36 UTC | |
|
Re: Help with Concatenates script
by chrism01 (Friar) on Apr 04, 2008 at 01:03 UTC | |
|
Re: Help with Concatenates script
by jwkrahn (Abbot) on Apr 04, 2008 at 03:51 UTC |