macos 如何创建每天上午 12:20 运行的 cron 作业?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7326554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:23:58  来源:igfitidea点击:

How do I create a cron job that will run everyday at 12:20am?

macosshellcroncrontab

提问by Matt Elhotiby

I am trying to write a cron job on my Mac OS X machine that will run a Ruby script at 12:20am everyday.

我正在尝试在我的 Mac OS X 机器上编写一个 cron 作业,该作业将在每天凌晨 12:20 运行一个 Ruby 脚本。

This is what I need to run but I don't know the syntax or the command to use on the Mac:

这是我需要运行的,但我不知道在 Mac 上使用的语法或命令:

/usr/bin/ruby /Users/tamer/scripts/sftp.rb

I read about doing crontab -ebut do I need to do something afterwards?

我读过关于做的事,crontab -e但我之后需要做些什么吗?

回答by Bohemian

The crontab for "everyday at 12:20am" is

“每天上午 12:20”的 crontab 是

20 0 * * *

The whole line in crontab would then be

crontab 中的整行将是

20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb

回答by Jonathan Leffler

The crontab entry should look like:

crontab 条目应如下所示:

20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb

This assumes that you don't need any other environment variables to make it all work. If you do need other variables, then create an environment-setting shell script which then executes the Ruby program and script.

这假设您不需要任何其他环境变量来使其全部工作。如果您确实需要其他变量,则创建一个环境设置 shell 脚本,然后执行 Ruby 程序和脚本。

To submit the job, I usually use:

要提交作业,我通常使用:

crontab -l > x3
echo  "20 0 * * * /usr/bin/ruby /Users/tamer/scripts/sftp.rb" >> x3
crontab < x3
rm x3