bash 如何每天晚上 10 点运行一次 cron
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8938120/
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
How to run cron once, daily at 10pm
提问by Marc Simon
I had entered:
我已经进入:
* 22 * * * test > /dev/null
However, I am being notified via email that this is running every minute. I am confused I guess because I thought this was correct for what I am wanting.
但是,我通过电子邮件收到通知,这每分钟都在运行。我想我很困惑,因为我认为这对我想要的来说是正确的。
回答by Marc Simon
It's running every minute of the hour 22 I guess. Try the following to run it every first minute of the hour 22:
我猜它在 22 小时的每一分钟都在运行。尝试以下操作,每 22 小时的第一分钟运行一次:
0 22 * * * ....
回答by Abdalla Mohamed Aly Ibrahim
Here are some more examples
这里还有一些例子
Run every 6 hours at 46 mins past the hour:
46 */6 * * *
Run at 2:10 am:
10 2 * * *
Run at 3:15 am:
15 3 * * *
Run at 4:20 am:
20 4 * * *
Run at 5:31 am:
31 5 * * *
Run at 5:31 pm:
31 17 * * *
每小时 46 分钟后每 6 小时运行一次:
46 */6 * * *
在凌晨 2:10 运行:
10 2 * * *
在凌晨 3:15 运行:
15 3 * * *
凌晨 4:20 运行:
20 4 * * *
早上 5:31 运行:
31 5 * * *
下午 5:31 运行:
31 17 * * *
回答by jaypal singh
To run once, daily at 10PM you should do something like this:
要运行一次,每天晚上 10 点,您应该执行以下操作:
0 22 * * *
Full size image: http://i.stack.imgur.com/BeXHD.jpg
全尺寸图片:http: //i.stack.imgur.com/BeXHD.jpg
Source:softpanorama.org
资料来源:softpanorama.org
回答by zee
Here is what I look at everytime I am writing a new crontab entry:
这是我每次编写新的 crontab 条目时看到的内容:
To start editing from terminal -type:
从终端开始编辑 - 类型:
zee$ crontab -e
what you will add to crontab file:
您将添加到 crontab 文件的内容:
0 22 * * 0 some-user /opt/somescript/to/run.sh
What it means:
这是什么意思:
[
+ user => 'some-user',
+ minute => ‘0', <<= on top of the hour.
+ hour => '22', <<= at 10 PM. Military time.
+ monthday => '*', <<= Every day of the month*
+ month => '*', <<= Every month*
+ weekday => ‘*', <<= Everyday (0 thru 6) = sunday thru saturday
]
Also, check what shell your machine is running and name the the file accordingly OR it wont execute.
此外,检查您的机器正在运行的外壳程序并相应地命名文件,否则它不会执行。
Check the shell with either echo $SHELL
or echo $0
使用echo $SHELL
或检查外壳echo $0
It can be "Bourne shell (sh)
, Bourne again shell (bash)
,Korn shell (ksh)
..etc"
它可以是“Bourne shell (sh)
,Bourne again shell (bash)
,Korn shell (ksh)
..etc”
回答by Magesh Somasundaram
The syntax for crontab
crontab 的语法
* * * * *
Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute
Your syntax
你的语法
* 22 * * * test > /dev/null
your job will Execute every minute at 22:00 hrs all week, month and year.
您的工作将在每周、每月和每年的 22:00 每分钟执行一次。
adding an option (0-59) at the minute place will run it once at 22:00 hrs all week, month and year.
在分钟位置添加一个选项 (0-59) 将在整个周、月和年的 22:00 小时运行一次。
0 22 * * * command_to_execute