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

In reply to Command at a specific Date by giany

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.