linux - 如何使用 bash 脚本将 crontab 作业添加到 crontab?

标签 linux cron crontab ubuntu-16.04 ubuntu-server

我尝试了以下命令,crontab 停止运行任何作业: echo "@reboot/bin/echo 'test' >/home/user/test.sh"|定时任务-

在 Linux 中将作业添加到 crontab 的正确方法是什么?

最佳答案

我建议你阅读 Cron and Crontab usage and examples .

你可以运行这个:

➜ ( printf -- '0 4 8-14 * *  test $(date +\%u) -eq 7 && echo "2nd Sunday"' ) | crontab
➜  crontab -l
0 4 8-14 * *  test $(date +\0) -eq 7 && echo "2nd Sunday"            

或者

#!/bin/bash
cronjob="* * * * * /path/to/command"
(crontab -u userhere -l; echo "$cronjob" ) | crontab -u userhere -

希望这对您有所帮助。

关于linux - 如何使用 bash 脚本将 crontab 作业添加到 crontab?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42198960/

相关文章:

linux - 通过 UDP 在端口上接收消息的非阻塞服务

python - 路由器 cli 界面的 pxssh 登录问题

c - 将包含零的二进制文件写入 Linux 文件系统

c - open() 不设置 O_CLOEXEcflags

php cron 作业也执行 javascript

cron - 在重新启动之前让 cron 等待作业完成

r - Pandoc 同时使用 R markdown 和 cron 命令

cron - Jenkins cron 格式

django - 在 wsgi 上与 django 项目并行的正确方法

python - 错误的路径导致 python 程序使用 crontab 运行