giany has asked for the wisdom of the Perl Monks concerning the following question:
The test file contains some data and the last field $DATA contains a date ( 01:12:12:40) which is hour,day,month,minute. The problem is that I dont know what to do if $actdate != $DATE . Normally if its a smaller date then it should go with the last part of the code:#!/usr/bin/perl # # # use Time::Local; use Term::ANSIColor; use POSIX qw(strftime); open(IN,"test"); my $actdate = strftime "%H:%d:%m:%M", localtime; my $acthour = strftime "%H",localtime; my $actmonth = strftime "%d",localtime; my $actday = strftime "%m",localtime; my $actmin = strftime "%M",localtime; while( $line = <IN> ){ if ( $line =~ /^#./ ){ } elsif ( $line =~ /^[1-9]/ ) { ($IP,$MAC,$MINI,$MAXI,$VIRUS,$FULL,$BUN,$NAME,$DATA) = spl +it(/\ /,$line); ($HH,$ZZ,$MM,$Min) = split(/:/, $DATA); chomp($DATA); my $comm = "/sbin/iptables-save | /bin/grep $IP | /bin +/grep DNAT >/dev/null 2>&1"; my $comI = "/sbin/iptables -t nat -I PREROUTING -i eth +1 -m tcp -p tcp --dport 8080 -j DNAT --to-destination 10.0.0.251:80 - +s "; my $comD = "/sbin/iptables -t nat -D PREROUTING -i eth +1 -m tcp -p tcp --dport 8080 -j DNAT --to-destination 10.0.0.251:80 - +s "; if ( $actdate eq $DATE) { $check = system($comm); chomp($check); if ( $check == 0 ) { system("$comD $IP"); system("$comI $IP"); } else { system("$comI $IP"); } } else { $check = system($comm); chomp($check); if ( $check == 0 ) { system("$comD $IP"); } else { print "$NAME ok\n"; } } } }
But what if its a higher date? Maybe with the $actday,$actmonth,$acthour $ZZ,$MM,$HH variables? Any hints? Thxelse { $check = system($comm); chomp($check); if ( $check == 0 ) { system("$comD $IP"); } else { print "$NAME ok\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Command at a specific Date
by Hena (Friar) on Dec 12, 2005 at 10:33 UTC | |
by salva (Canon) on Dec 12, 2005 at 13:12 UTC | |
|
Re: Command at a specific Date
by tirwhan (Abbot) on Dec 12, 2005 at 10:28 UTC | |
|
Re: Command at a specific Date
by gjb (Vicar) on Dec 12, 2005 at 13:34 UTC |