Techtrekking

mynotes cronjob

By Pravin

open a crontab

crontab -e

Run everyday

# every week day 0 9 * * * /home/ubuntu/novanenv/bin/python /path/to/your/script.py >> /path/to/your/logfile.log 2>&1 # every working day 0 9 * * 1-5 /home/ubuntu/novanenv/bin/python /path/to/your/script.py >> /path/to/your/logfile.log 2>&1 # weekly once on monday 0 9 * * 1 /home/ubuntu/novanenv/bin/python /path/to/your/script.py >> /path/to/your/logfile.log 2>&1
PositionNameValue RangeDescription
1stMinute0-59Specific minute.
0 = Top of the hour.
30 = Half past.
* = Every single minute.
2ndHour0-2324-hour format.
0 = Midnight.
9 = 9 AM.
13 = 1 PM.
23 = 11 PM.
3rdDay of Month1-31Specific Calendar Date.
Use this if you want to run on the "1st of the month" or "15th of the month".
4thMonth1-12The Month.
Use this to run only in "December" or "January".
5thDay of Week0-6The Weekly Cycle.
0 or 7 = Sunday
1 = Monday
5 = Friday

once cronjob changes are done, restart the cron

sudo systemctl status cron sudo systemctl stop cron sudo systemctl start cron sudo systemctl restart cron

check cronjob logs

grep CRON /var/log/syslog

How to check python script status triggered by cron

# check python programs ps aux | grep python # check specific script ps aux | grep my_script.py #output will be as below ubuntu 12345 0.5 python3 /path/to/my_script.py

This run can be killed by following

# kill by script name pkill -f my_script.py # kill by process id kill 12345 # force kill kill -9 12345
Comments
No comments yet. Be the first to comment!
Leave a Comment
Your comment will be visible after approval.