[英]cron (reboot job) and wget (extract files) don't “get” along
我正在努力让它发挥作用,但我似乎无法做到这一点。
我得到了这个 Raspberry Pi,我想在重新启动时将照片从保管箱链接下载到特定文件夹中。
sudo crontab -e
@reboot /home/pi/path/to/dir/with/photos/scripts.sh
脚本.sh
#!/bin/bash
set -x
cd /home/pi/path/to/dir/with/photos/
# delete all photos and download and convert them again
rm -f /home/pi/crontab.refresh.log || true
sh /home/pi/path/to/dir/with/photos/refreshPhotos.sh > /home/pi/crontab.refresh.log
# convert all photos to bmp (and scale them)
rm -f /home/pi/crontab.convert.log || true
/usr/bin/python2.7 /home/pi/path/to/dir/with/photos/convertPhotos.py > /home/pi/crontab.convert.log
刷新照片.sh
#!/bin/bash
# clear the "old" ones
rm -f *.JPG || true
rm -f *.jpg || true
# Get the "fresh" ones
wget -qO- https://www.dropbox.com/sh/AAA/BB -P /home/pi/path/to/dir/with/photos/ | bsdtar -xvf-
wget
使用-qO-
和| bsdtar -xvf-
看起来有点时髦。 | bsdtar -xvf-
- 这是为了避免将它们放入文件夹 AAA 和 BBB。
从运行脚本
/home/pi/path/to/dir$ bash /with/photos/scripts.sh
工作得很好。 但是重新启动似乎不起作用(它只会删除旧照片而不会下载新照片。
任何可以解决我的问题的帮助将不胜感激!
cron 通常启动一个非常基本的 shell 几乎没有任何环境变量。 为确保它获得正确的环境,请按照此操作并添加
$HOME/.profile;
就在@reboot上的命令之前,所以
@reboot $HOME/.profile; /home/pi/path/to/dir/with/photos/scripts.sh
@Philippe 的建议帮助我弄清楚这是因为一旦 cron 作业开始就建立了 wifi 连接。
这成功了:
脚本.sh
#!/bin/bash
set -x
cd /home/pi/path/to/dir/with/photos/
# remove all old logs first
rm -f /home/pi/crontab.*.log || true
rm -f /home/pi/crontab.log || true
# delete all photos and download and convert them again
rm -f /home/pi/crontab.refresh.log || true
while ! ping -c1 dropbox.com >> /home/pi/crontab.wifi.log # Need to make sure that the internet connection is there before starting
do echo "no connection to dropbox yet"
done
sh /home/pi/path/to/dir/with/photos/refreshPhotos.sh >& /home/pi/crontab.refresh.log
非常感谢@Philippe !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.