-2

Python script is not being run, all other functions are running and stand alone script runs but combined... nada. Initially it was */30 * * * * screen python ~/db_preset.py (Yes there was new line after)

Then I packed the script into bash script:

#!/bin/sh
if ps -ef | grep -v grep | grep db_preset.py ; then
        :
else
        date >> ~/cron_log.log
        screen python /home/account/db_preset.py     
fi

and invoked it with */30 * * * * bash ~/scripts.sh

Date gets logged, so it gets to that part but script is never launched

When I try simple cron like */2 * * * * date >> ~/cron_log.log, works just fine

Edit

I tried changing python path to /usr/local/bin/python2.7 /home/account/db_preset.py; touch ~/a_command_has_run

File gets created, so line is run afterall Code is also good when run manually

rodling
  • 121
  • 1
  • 6

2 Answers2

3

It's likely a pathing issue.

do: which python

It's likely to be at /usr/bin/python.

Then change your script to call the full path, ie: /usr/bin/python /home/account/db_preset.py

Dave Holland
  • 1,898
  • 1
  • 13
  • 17
2

Error messages from commands started through cron are sent by mail. If you look in the mail spool, you should be finding this error message: Must be connected to a terminal.

This is because you are trying to start the screen attached, which requires a terminal, and jobs run through cron have no terminal.

Starting new screen sessions from cron sounds dubious. You should probably just leave out the screen part. If you absolutely must start screen without a terminal, then start it detached. For example:

screen -dmS somename python ~/db_preset.py
kasperd
  • 29,894
  • 16
  • 72
  • 122