简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM