Cron Job无法用于Shell脚本或ruby脚本Mac OS

我有一个名为automated_script.rb的红宝石脚本

我也有一个名为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

所以我知道它是活动的。

感谢您的帮助,谢谢!

编辑

这是我的红宝石文件里面的内容

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 
)
xiezhanliang 回答:Cron Job无法用于Shell脚本或ruby脚本Mac OS

您不需要shell即可从cron执行红宝石。您应该能够将ruby和文件传递到crontab。

* * * * * ruby /Users/angelgarcia/Desktop/automated_script.rb 

请注意,这将使用您设置的默认系统ruby版本。

本文链接:https://www.f2er.com/3131365.html

大家都在问