My objective here is to: 1) Clean this script up
#!/usr/bin/perl use warnings; use strict; # THIS SCRIPT CONCATENATES DATA FOR 1 WEEK OF RELIANT TRUST DATA AND S +ENDS TO NDM # my $MT = 'my.email.com'; # Mail Alias used for sendin +g emails my $ASL = 'app-server'; my @BFL = qw( name1.log name2.log ); # START TIME AND DATE VARIABLES # my ( $mday, $mon, $year, $wday ) = ( localtime $^T - 3600 * 24 )[ 3 .. + 6 ]; # Saturday only exit 0 if $wday != 5; # # END TIME AND DATE VARIABLES for my $f ( @BFL ) { my $catfile = sprintf '%s.%d%02d%02d', $f, $year + 1900, $mon + 1, + $mday; open my $CAT, '>', $catfile or die "Cannot open '$catfile' $!"; for my $i ( 5 .. 8 ) { for my $dd ( reverse 1 .. 7 ) { # Number of days to go back + for process my ( $mday, $mon, $year ) = ( localtime $^T - $dd * 3600 * + 24 )[ 3 .. 5 ]; my $fileext = sprintf '%s.myservername%d.%d%02d%02d', $f, +$i, $year + 1900, $mon + 1, $mday; open my $IN, '<', "$fileext.$ASL$i" or warn "Cannot open ' +$fileext.$ASL$i' $!"; print $CAT while <$IN>; } } # the cat-ed file is produced: scp it my $filetoput = "/home/echxfr/$catfile"; my @cmd = ( '/usr/bin/scp', $catfile, "cduser\@ndm:$filetoput", ); my $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"; } if ( -z $catfile ) { 0 == system '/bin/mailx', '-s', "ERROR: Reliant SCP Log file $ +catfile sent to ndm is empty", $MT or warn "system 'mailx' failed: $?"; } }
In reply to Re: Help with Concatenates script
by jwkrahn
in thread Help with Concatenates script
by wskibum
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |