1

I have a bash script taking a picture with my raspberry pi camera and measuring the humidity and temperature with a python script.

#!/bin/bash

raspistill -o /var/www/image.jpg -t 1000
python Adafruit_Python_DHT/examples/AdafruitDHT.py 2302 4 | tr -s ' ' | grep -o '[0-9]\+\.[0-9]\+' > /var/www/sensor.out

The bash script works if I execute it normally, but if I put it in crontab (as root) it still executes the first line but the second line returns an empty file. It removes but does not replace the old info.

pi@rpi ~ $ sudo crontab -e
 GNU nano 2.2.6                              File: /tmp/crontab.Y0eieF/crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/pi


*/1 *  *   *   *     /home/pi/testcron.sh

I have no idea why it isn't working, is it maybe because of the named pipes?

1
  • Use the absolute path to the input file in the second line. Commented Jun 21, 2014 at 9:10

1 Answer 1

1

You have a relative path specified in your script, but you don't start in your home directory from the cronjob. Use absolute paths in your bash script.

Sign up to request clarification or add additional context in comments.

2 Comments

In general, the shell environment is pretty spartan inside a cronjob. You don't get your user's environment. Try running a "set" command redirected to a file as a cronjob to see what it looks like. This will help you tailor your scripts to work correctly.
Oh I forgot about the path after trying to get cron working. Thanks for your help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.