user967587
user967587

Reputation: 33

Python script in bash with crontab doesn't work but without crontab it does

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?

Upvotes: 1

Views: 435

Answers (1)

CDahn
CDahn

Reputation: 1876

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.

Upvotes: 1

Related Questions