Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view a cron job running currently?

Tags:

linux

cron

I have a cron job set up for daily execution (on my own ubuntu, just for trial) like so:

0 0 * * * /path/exec.sh

It is been set for daily execution. I usually open my machine around 8a.m. I would like to find out
- what time my cron job ran, if it has already run ?
- I would also like to see if any of my cron job is running at the moment?

Is there a way to find out IF a cron job is actually running at the moment?

like image 869
CoderBC Avatar asked Apr 27 '16 07:04

CoderBC


People also ask

How do you check if a cron job is currently running?

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). Or even better, have your cron job write a log file with timestamps so you can see how it's progressing.

How do you display your current crontab?

View Current Logged-In User's Crontab entries : To view your crontab entries type crontab -l from your unix account. View Root Crontab entries : Login as root user (su – root) and do crontab -l. To view crontab entries of other Linux users : Login to root and use -u {username} -l.


2 Answers

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

like image 110
Cwissy Avatar answered Oct 07 '22 03:10

Cwissy


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)

like image 21
abkrim Avatar answered Oct 07 '22 03:10

abkrim