如何在Linux centos中安排shell脚本?

Meg*_*rma 2 linux shell scheduling

我有一个脚本,我需要每天安排.如何在centos中安排脚本.就像我想在每天上午10点运行该脚本一样,我可以将脚本的输出存储在日志文件中.

怎么做到这一点?

谢谢

jay*_*ngh 7

要安排脚本,您需要使用crontab.您可以通过执行以下操作添加计划条目:

crontab -e
Run Code Online (Sandbox Code Playgroud)

进入内部后,cron表单中的接受模式:

<Minute> <Hour> <Day> <Month> <Day of Week> <Command>
Run Code Online (Sandbox Code Playgroud)

所以上午10点正确的crontab条目就是

0 10 * * * /path/to/script
Run Code Online (Sandbox Code Playgroud)

如果你想捕捉的输出可以在里面指定的日志文件cron

0 10 * * * /path/to/script > /path/to/log/output.log
Run Code Online (Sandbox Code Playgroud)

只需确保she-bang在脚本中添加标题即可.或者,您可以通过以下方式指定shell解释器cron:

0 10 * * * bash /path/to/script > /path/to/log/output.log
Run Code Online (Sandbox Code Playgroud)