Run python script with crontab

1. Create Python script, and make sure it works

import os
# it has to be the full path not ./location or else the crontab wont work
f = open('/home/user/test.txt','a') #open file to append, create it if doesn't exist
f.write("balls\n") #write

2. Edit crontab
$ crontab -e

3. Then it will ask what editor you wish to use. I selected nano.

4. Insert into file
# every minute
* * * * * python /home/user/

# a random cron example
* * * * * uptime > /opt/lampp/database_backup/text.txt

ubuntu cronhowto link

For the log, cron ran:
$ tail -f /var/log/syslog | grep CRON

Leave a Reply