简体   繁体   English

Cron 作业不适用于 shell 脚本或 ruby 脚本 mac os

[英]Cron Job not working for shell script or ruby script mac os

I have a ruby script called automated_script.rb我有一个名为automated_script.rb的ruby 脚本

I also have a shell script called automated_script.sh我还有一个名为automated_script.sh的shell脚本

Both of these files are located on my desktop, for now.目前,这两个文件都位于我的桌面上。

whenever I run ruby automated_script.rb , the script works as expected (all it does is send a text message using the twilio api)每当我运行ruby automated_script.rb时,脚本都会按预期工作(它所做的只是使用 twilio api 发送短信)

This is what I have in automated_script.sh这就是我在automated_script.sh中所拥有的

#!/bin/zsh

/Users/angelgarcia/.rvm/rubies/ruby-2.6.3/bin/ruby /Users/angelgarcia/Desktop/automated_script.rb 

when I navigate to my desktop in the terminal and run, ./automated_script.sh it works.当我在终端导航到我的桌面并运行时, ./automated_script.sh它可以工作。

when I simply run:当我简单地运行时:

/Users/angelgarcia/.rvm/rubies/ruby-2.6.3/bin/ruby /Users/angelgarcia/Desktop/automated_script.rb 

in the terminal, this works too.在终端中,这也有效。

However , in my crontab, I have this:但是,在我的 crontab 中,我有这个:

* * * * * /Users/angelgarcia/Desktop/automated_script.sh

This does not work as expected.这不能按预期工作。

Simply running this works: /Users/angelgarcia/Desktop/automated_script.sh But for some reason, when I put it in the crontab, it doesn't run every minute.简单地运行这个就可以了: /Users/angelgarcia/Desktop/automated_script.sh但是由于某种原因,当我把它放在 crontab 中时,它并不是每分钟都运行。

When I run crontab -l in my terminal, I get this:当我在终端中运行crontab -l时,我得到了这个:

* * * * * /Users/angelgarcia/Desktop/automated_script.sh

So I know it's active.所以我知道它是活跃的。

Any help is appreciated, thanks!任何帮助表示赞赏,谢谢!

EDIT编辑

here is whats inside of my ruby file这是我的 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 
)

You don't need shell to execute ruby from cron.您不需要 shell 从 cron 执行 ruby。 You should be able to just pass ruby and a file to your crontab.您应该能够将 ruby 和一个文件传递给您的 crontab。

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

Note, this will use whatever your default system ruby version is set to.请注意,这将使用您的默认系统 ruby 版本设置的任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM