This is my print.py file
#!/usr/bin/env python2.7
from datetime import datetime
fn = 'msgs.txt'
f = open(fn, 'aw')
f.write('%s\n' % datetime.now())
f.close()
I want to run this silly script every 5 minutes. I did
sudo crontab -e
and added
*/5 * * * * /home/msh/sandbox/python/cron/run.sh
where run.sh is just
#!/bin/sh
python /home/msh/sandbox/python/cron/print.py
Files run.sh
and print.py
have executing permission.
However I don't see the script running because there is no input in msgs.txt
. Did I set up cron job correctly?
You need to give the full path to the target file in your cron script; this is to make sure you know where to check if its being written or not. Try changing fn = 'msg.txt'
to fn = '/home/msh/sandbox/python/cron/msg.txt'
This isn't important in your simple example, but you aren't running the script with python2.7
, you are running it with python
(which may be a different version).
As you have marked the file as executable, your cron task should be simply /home/msh/sandbox/python/cron/print.py
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments