0

Apologies, but a bit of a newbie when it comes to Ubuntu but I am going out of my head with this and need some help.

I have a script that I have written that works is I execute it by itself. :-

#!/bin/bash                                                                                                                                                                                   
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:~/bin                                                                                                                             
cd environments                                                                                                                                                                               
cd Garmin                                                                                                                                                                                     
cd Sync                                                                                                                                                                                       
python3 sync.py -f 2018-01-01 -t 2025-01-01

The issue is that I have a crontab job for it to run every hour, but it is not running (as it is not updating weight measurements)

00 * * * * ~/bin/sync.sh 

Can anyone help. Apologies but just starting out if the coding looks long winded.

Thanks

JJ28
  • 1
  • Have you tried using the full path rather than trying to cd to the directory? I would call it like so

    python3 /full/path/to/sync.py -f 2018-01-01 -t 2025-01-01 Also, if PATH is being set in the script, I don't see how cron would know where it is.

    – Gordster Jun 14 '19 at 22:10
  • Hi. Yeah tried that but I get an error message for 2 of the files in another directory. I have changed the permission for those so it can read, execute and write but still no joy. If I am in the directory (Sync) everything runs fine. Have tried SUDO swell, but no luck. Can run the script and it runs perfectly, but just in crontab – JJ28 Jun 14 '19 at 22:33
  • 1
    Have you tried redirecting output & error to a log file to see what's happening? Also, does the python script depend on anything in the environment? Try running the script interactively with a cleaned environment, and see if it works this way: env -i ~/bin/sync.sh – Gordon Davisson Jun 14 '19 at 22:50

1 Answers1

0

I came across this post which should help point you in the right direction.

If the first answer does not help fix you issue then you can use the second answer which is written by Byte Commander. Byte Commander shows a nice way to accomplish your goal without having to deal with cron. You would just have to change the 10m to 60m or so

To avoid cron, you could also call your script in an infinite loop with a delay of 10 >minutes.

If you want to launch the script again 10 minutes after the previous instance exited, >use this:

while true ; do /PATH/TO/SCRIPT.PY ; sleep 10m ; done

However, if you want to launch the script every 10 minutes on the clock, no matter >how long the last instance was running (or whether it still is running), you must >execute the script in background and sleep in parallel by replacing the ; with an &:

while true ; do /PATH/TO/SCRIPT.PY & sleep 10m ; done

Gordster
  • 1,719
  • Hi Thanks for this. Tried all the CRON actions as you said but still no joy. But the infinite look works - thank you so much for this. It's fine as this is the only thing it will be using. – JJ28 Jun 16 '19 at 14:47