如何在没有交互式编辑器的情况下使用 Bash 自动创建 cron 作业? [英] How to create a cron job using Bash automatically without the interactive editor?

查看:27
本文介绍了如何在没有交互式编辑器的情况下使用 Bash 自动创建 cron 作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

crontab 是否有一个参数可以在不使用编辑器的情况下创建 cron 作业(crontab -e).如果是这样,从 Bash 脚本创建 cronjob 的代码是什么?

Does crontab have an argument for creating cron jobs without using the editor (crontab -e). If so, What would be the code create a cronjob from a Bash script?

推荐答案

您可以按如下方式添加到 crontab:

You can add to the crontab as follows:

#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron
#install new cron file
crontab mycron
rm mycron

<小时>

Cron 行说明

* * * * * "command to be executed"
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

来源 nixCraft.

这篇关于如何在没有交互式编辑器的情况下使用 Bash 自动创建 cron 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆