I have a problem with a cron task, i tried a lot of things but nothing works. I'm on Raspbian and i use crontab -e to edit my cron.

I need to run 2 scripts every 1 minute. It works well for the Python script (.py), impossible for the SH.

*/1 * * * * /home/root/domoticz/scripts/DOMOTICZ/Home.py
*/1 * * * * /home/pi/Get_temp_bleville.sh

I read a lot of forums, I added #!/bin/sh or #!/bin/bash in the top of the script, I tried a chmod 777 Get_temp_bleville.sh for testing purposes.

I tried to change the localtion, the group owner (pi and root)... and these syntaxes :

*/1 * * * * /bin/sh /home/pi/Get_temp_bleville.sh
*/1 * * * * /bin/bash /home/pi/Get_temp_bleville.sh
*/1 * * * * bash /home/pi/Get_temp_bleville.sh
*/1 * * * * sh /home/pi/Get_temp_bleville.sh
*/1 * * * * root /home/pi/Get_temp_bleville.sh

Nothing to do :(

$ ls
-rwxrwxrwx 1 pi   pi    228 déc.  19 21:19 Get_temp_bleville.sh

When i start the script directly by ./script or bash or sh, it works!

Here's the shell script

The SH script :

# Get Weather by API
wget -N http://api.wunderground.com/api/3b048a56ce883f41/conditions/q/pws:I76DOLLE2.json

# Get Temperature and parse file + create txt file with the temparature value
cat pws\:I76DOLLE2.json | jq '.current_observation.temp_c' | xargs echo > Temp_bleville.txt

What can I do?

migrated from askubuntu.com Dec 19 '17 at 21:14

This question came from our site for Ubuntu users and developers.

  • 3
    You're running scripts every minute? I'd think very carefully about this -- are you sure this is what you want and there's no better way of doing things? – Kaz Wolfe Dec 19 '17 at 21:04
  • Yes every minute because it's to refresh a captor value for my home automation system. But i can change for 5 minutes max, it's possible but i don't think that will solve my problem. I have no problem with my Python script, all my SH scripts have the same problem. I don't think that permissions are bad, maybe a path somewhere... impossible to find. – kikeklaus Dec 19 '17 at 21:08
  • Does system logs have any error? /var/logs/system.log? – Praveen Premaratne Dec 19 '17 at 21:12
  • Yes, i enable logs here : /var/log/cron.log – kikeklaus Dec 19 '17 at 21:13
  • 1
    Post the script here. Also, analyze it for errors at shellcheck.net – glenn jackman Dec 19 '17 at 21:15

When debugging shell scripts not interactively run, I always start off with the

#!/bin/sh # or other shell

but immediately follow it with

# this redirects output to your log file & sends errors there also
exec > [full path of your own log file] 2>&1 
# This makes the script output each command as it is executed
set +x

Given that, either set your paths or put the full path name in front of your commands as in:

export PATH=/bin:/usr/bin


/usr/bin/wget -N http://api.wunderground.com/api/3b048a56ce883f41/conditions/q/pws:I76DOLLE2.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.