2

I am trying to repeatedly execute python script(s) using Cron. I have written a shell script that calls that/these python script(s). I have made the shell script as an executable and works perfect both in terminal and just by clicking to execute.

I have changed the crowntab to call my shell script at a specific - usually in a minute or two - time intervals to see if it is working. However, it seems my script is not being executed properly.

My python script is a long one and it also has local python functions that it calls. Nevertheless, I created a short python program as well as a shell script to call it for the purpose of finding out if the cron works and, it seems, that it is being called as intended.

Why my python/shell script is not being called properly for execution? If I call a shell script, do I still need to include path for the cron to see?

My crontab:

20 13 * * * /my/full/path/to/the/shell_script.sh

My shell script/file:

#!/bin/bash
cd /full/path/to/the/python_script_folder
sudo python3 python_script.py argument

RPi3 /var/log/syslog:

Jan 23 20:13:01 raspberrypi cron[477]: (pi) RELOAD (crontabs/pi)
Jan 23 20:13:01 raspberrypi CRON[3851]: (root) CMD (/etc/myDevices/crontab.sh)
Jan 23 20:13:01 raspberrypi CRON[3854]: (pi) CMD (/my/full/path/to/the/shell_script.sh)

Any help is appreciated. If you need any additional information, please let me know. Thank you.

1
  • 1
    Is sudo asking for a password or cd failing? bash -x might be informative.
    – thrig
    Commented Jan 23, 2017 at 21:46

1 Answer 1

0

As @thrig mentioned - sudo is probably asking for password and bash -x will give additional info of what is executed and what is the output. First of all, it's a good practice to redirect cron output, e.g.

20 13 * * * /my/full/path/to/the/shell_script.sh > ${HOME}/cron.log 2>&1

This will give you output of the script logged in the file.

I would:

  1. place the entry in crontab of the user that needs to run it.
  2. drop the wrapper and set the command as 'python3 /path/to/script.py args'
1
  • The log file shows what is the problem. Thanks! Commented Jan 24, 2017 at 12:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .