0

When I am SSH'd into my Ubuntu 6.4 VM and run python nomi.py, my script executes as it should.

I set up my crontab file as follows in order to run the script every 15 mins:

# m h  dom mon dow   command

*/15 * * * * /usr/bin/python home/cron1admin/nomi.py

Is there anything wrong with how I set up the crontab file? Do I need to do anything after the crontab file is created?

The nomi.py file sends data to Google Analytics, and when I run the script, the data goes through. When I attempt to let the cron job run the script, nothing happens.


ps aux | grep cron table

root      1029  0.0  0.0  19120   932 ?        Ss   Jun26   0:01 cron
root      5896  0.0  0.3  73448  3724 ?        Ss   16:41   0:00 sshd: cron1admin [priv]
1000      6084  0.0  0.1  73448  1656 ?        S    16:42   0:00 sshd: cron1admin@pts/0
root      6745  0.0  0.3  73448  3628 ?        Ss   18:07   0:00 sshd: cron1admin [priv]
1000      6926  0.0  0.1  73448  1552 ?        S    18:07   0:00 sshd: cron1admin@pts/1
1000      7065  0.0  0.0   9392   944 pts/1    S+   18:21   0:00 grep --color=auto cron
metersk
  • 11,803
  • 21
  • 63
  • 100

1 Answers1

1

The following question suggests that you should use absolute paths instead of relying on ~ to expand to your home directory.

Also make sure cron is actually running. You can do this by grepping for the cron process. On Ubuntu Linux, I usually use the following command.

ps aux | grep cron
Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329
  • how do i ensure cron is running? i get this error when i execute `sudo cron`: `cron: can't lock /var/run/crond.pid, otherpid may be 1029: Resource temporarily unavailable` – metersk Jul 01 '14 at 22:20
  • 1
    @Barnaby, I usually do `ps aux | grep cron` and see if the `cron` process is there. – merlin2011 Jul 01 '14 at 22:20
  • I get an output that is a pretty large table. would nothing show if it wasn't therre? – metersk Jul 01 '14 at 22:23
  • added the table to my question – metersk Jul 01 '14 at 22:24
  • @Barnaby, There is a `cron` process in that output, so I think you're good on that count. Did you already try changing the `~` to the full path? – merlin2011 Jul 01 '14 at 22:28
  • i changed the full path and i also noticed that i had `user/bin/python` instead of `usr/bin/python`. now do i need to wait the 15 minutes to see if it will work or should it run once automatically? – metersk Jul 01 '14 at 22:30
  • 1
    @Barnaby, If you want it to run more frequently than on the `15`, you will have to change the frequency temporarily, or google for a way to force an earlier run. – merlin2011 Jul 01 '14 at 22:34
  • Okay i guess i was asking how to force an earlier run...will do some research, thanks! – metersk Jul 01 '14 at 22:34
  • still not running after 15 mins. anything else to try? – metersk Jul 01 '14 at 22:43
  • @Barnaby, How are you verifying whether it runs or not? – merlin2011 Jul 01 '14 at 22:46
  • well I'm not seeing the data in real time google analytics as I do when I just run the script without cron. Is there a better way to check? – metersk Jul 01 '14 at 23:03
  • @Barnaby, If you write a timestamp to a log file every time the script starts running, and then write another timestamp every time the script finishes running, you can debug whether the problem is that the script didn't run at all or the script is trying to do something which is interacting badly with cron. – merlin2011 Jul 01 '14 at 23:07
  • i tried `*/1 * * * * echo 'Hello'` which did not work. so i feel like this is a cron issue, not a script issue – metersk Jul 02 '14 at 17:32