Hello,
I`m trying to write a script that will execute a command at a specific date.
#!/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";
}
}
}
}
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:
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?
Thx