Reputation: 105
I have a Perl script which runs 2 times a day using cron. I would like to know a command to check when my Perl program last ran. Does such command exists? If not, can you guys please tell me how will I accomplish this task?
Upvotes: 2
Views: 388
Reputation: 709
To answer your first question, no, there is not a generalized way to know the last time a program was run. And it's more complicated in this case, since a perl script isn't really a program - the perl
interpreter is the executable and the script is the input to the interpreter. So you'd really want to know the last time the perl
interpreter was run and executed your script.
Some mechanisms that run other programs (like cron
) may keep log files that record when programs are run (and maybe their exit code or other information about the execution). Note: this would not log every time this program was run - just when it was executed via cron
. Similarly, you could add some logging to your script to write to a file that it was run. Though if the script failed to run, or could not write to the log file (say, for instance, your permissions were messed up), then it would not log that execution. So it's not a fool-proof solution. But it might be enough for your purposes.
As for cron logging, you can man cron
or man crontab
, or look at some of the SO questions directly about cron logging. For example,
cron jobs - how to log?
Upvotes: 0
Reputation: 118605
At the top of your script, put
open LAST, ">", "/tmp/last.time.the.program.ran";
print LAST scalar localtime;
close LAST;
Now the command to see when your program last ran is
$ cat /tmp/last.time.the.program.ran
(You could also poke around /var/log/cron
)
Upvotes: 2