【发布时间】:2020-03-06 01:47:18
【问题描述】:
我有一个名为 automated_script.rb 的 ruby 脚本
我还有一个叫做automated_script.sh的shell脚本
目前这两个文件都位于我的桌面上。
每当我运行 ruby automated_script.rb 时,脚本都会按预期工作(它所做的只是使用 twilio api 发送短信)
这就是我在automated_script.sh中的内容
#!/bin/zsh
/Users/angelgarcia/.rvm/rubies/ruby-2.6.3/bin/ruby /Users/angelgarcia/Desktop/automated_script.rb
当我在终端导航到我的桌面并运行时,./automated_script.sh 它可以工作。
当我简单地运行时:
/Users/angelgarcia/.rvm/rubies/ruby-2.6.3/bin/ruby /Users/angelgarcia/Desktop/automated_script.rb
在终端中,这也可以。
但是,在我的 crontab 中,我有这个:
* * * * * /Users/angelgarcia/Desktop/automated_script.sh
这没有按预期工作。
只需运行此程序即可:/Users/angelgarcia/Desktop/automated_script.sh
但是由于某种原因,当我把它放在 crontab 中时,它并不是每分钟都运行。
当我在终端中运行 crontab -l 时,我得到了这个:
* * * * * /Users/angelgarcia/Desktop/automated_script.sh
所以我知道它是活跃的。
感谢任何帮助,谢谢!
编辑
这是我的 ruby 文件里面的内容
require 'twilio-ruby'
account_sid = 'xxx'
auth_token = 'xxx'
@client = Twilio::REST::Client.new account_sid, auth_token
@client.messages.create(
from: '999',
to: '999',
body: message
)
【问题讨论】:
-
您可以检查 cron 日志文件中的错误。一个常见的错误是使用相对路径而不是绝对路径,例如在您的automated_script.rb 中。
-
如果我们能看到automated_script.rb在做什么也可能会有所帮助。
-
@Sergio 我会试着检查一下,谢谢
-
@lacostenycoder 我已经添加了 ruby 脚本
-
crontab 是否配置为您尝试直接运行的同一用户?在某些情况下,如果用户不同,可能是权限问题