How to view a cron job running currently?
If you are just interested in knowing if your cronjob is currently running and when it last started, then I find the following the easiest way:
0 0 * * * touch /path/cron.start; /path/exec.sh; touch /path/cron.end
This will create a file /path/cron.start
with a timestamp which is the start time. When the job finishes, the file /path/cron.end
will have the timestamp when the cron finished. So a simple ls -lrt /path/cron.{start,end}
will tell you when the job started and if it is still running (the order will tell you if it is still running).
to check if cron is actually running anything at this moment in time (works on ubuntu)
pstree -apl `pidof cron`
and you'll either get
2775,cron # your pid (2775) will be different to mine :-)
or a tree output with all the child processes that cron is running (it may not name them if you don't have sufficient privileges) and as Hamoriz says the logs are in /var/log/syslog so
grep CRON /var/log/syslog
will get you the logs just for cron
I would also like to see if any of my cron job is running at the moment?
ps aux |grep "path/exec.sh"
what time my cron job ran ?
Cron log only show when start task off crond, not log when end. You need put this on your task or embedded your task en one scritp with control time of start and end.
if it has already run ?
cat /path/logs/messages or /path/logs/file when your system put logs of crond (this depends on your distribution settings or your computer)