1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #!/usr/bin/perl -w
use LWP::Simple;
#### README: (optional) change these to a directory where you want them to be... ie: /var/log
$logfile = '/var/log/day.log';
$dayfile = '/var/log/day.txt';
#clear the logfile
clear();
mark("START"," --> ","check actual weekday !");
#read the previous day
open S, "$dayfile";
$prev_day = <S>;
close S;
#get the current day
$day = date +%w; # 0 = sunday
# verification if actual weekday is or isn't equal to the obtained weekday.
if (!($day eq $prev_day)) {
mark("Put", "in", "correct dir !");
# execute
@args = ("executer ce que tu veux faire");
# check if failed
system(@args) == 0
or mark("WARNING","Store","FAILED !");
# if it does check what error
if ($? != 0) {
printf E "failed to execute, raison: $!\n";
}
elsif ($? & 127) {
printf E "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
printf E "-------- Child exited with value: %d\n", $? >> 8;
}
# Save new day to the $dayfile
if ($? == 0) {
open S, ">$dayfile";
print S $day;
close S;
print E "Previous day was = $prev_day ";
print E "New day = $day\n";
}
}
else {
mark("Done", " --> ", "still same day, etc... !");
}
close E;
# subroutines
sub mark {
my ($type, $code, $message) = @_;
open E, ">>$logfile";
print E localtime()."\t$type\t".$code."\t".$message."\n";
}
sub clear {
open E, ">$logfile";
close E;
} |
Partager