我在Raspberry Pi上有以下脚本来发送短信 . 如果我输入:python tides_sms.py,它会运行
问题是,我无法通过Crontab运行它(* * * * * / usr / bin / python /home/pi/python_files/tides_sms.py) . 该文件设置为:rwxr-xr-x
当我添加代码写入文件时,文件通过Crontab创建,但它不会发送短信 .
任何帮助赞赏 .
#!/usr/bin/python
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "**********************************"
auth_token = "********************************"
with open("tide_data.txt", "r") as file:
tides_array = file.read().splitlines()
tides_array.reverse()
elements = tides_array[0].split(' | ')
string=''
for element in elements:
string = '\n'.join([string, element])
client = TwilioRestClient(account_sid, auth_token)
message = client.sms.messages.create(body="Text from PI:\nTIDES" + string,
to="+44??????????",
from_="+44??????????")
1 回答
当脚本通过cron运行时,工作目录是
/
- 文件系统根目录 . 在脚本中使用绝对路径: