【发布时间】:2016-06-23 00:52:21
【问题描述】:
我正在运行一个连接相机的树莓派,并想使用 crontab 每小时自动上传一次拍摄的照片。
另一个shell脚本每6分钟拍摄一次图片,该脚本也由crontab控制并且工作正常。
上传文件的 python 脚本在从 shell 调用时按预期工作。它构建正确的文件名并上传它们。这是脚本:
#!/usr/bin/env python
import dropbox
import os.path
import time
#pictures are taken every 6 minutes so this is used to build the file names:
interval = ('00','06','12','18','24','30','36','42','48','54')
access_token = "my_token"
client = dropbox.client.DropboxClient(access_token)
#get current time
t = time.strftime("%Y-%m-%d_%H")
for x in interval:
#build file name:
file = t+x+'.jpg'
#check if file exsists:
if os.path.isfile(file):
#open file
pic = open(file, 'rb')
#upload picture:
response = client.put_file(file, pic)
print "picture " + file + " uploaded"
pic.close()
我在 crontab -e 中添加了以下内容(路径正确)。所以它应该在每小时 56 分钟上传一次
56 * * * * python /home/pi/Pictures/pyPictureUpload.py
但是,没有上传任何内容。我还在 shell 脚本中使用相同的命令进行了尝试,并在 crontab 中调用了 shell 脚本:
56 * * * * /home/pi/Pictures/runUpload.sh
这是非常短的 shell 脚本:
!/bin/bash
python /home/pi/Pictures/pyPictureUpload.py
当直接从 shell 调用时,所有脚本都会按预期工作,但 crontab 不会自动运行任何脚本。我做错了什么?
【问题讨论】:
标签: python linux bash raspberry-pi crontab