How do I create a crontab through a script

前端 未结 12 1046
再見小時候
再見小時候 2020-11-28 01:36

I need to add a cron job thru a script I run to set up a server. I am currently using Ubuntu. I can use crontab -e but that will open an editor to edit the curr

12条回答
  •  难免孤独
    2020-11-28 02:39

    Crontab files are simply text files and as such can be treated like any other text file. The purpose of the crontab command is to make editing crontab files safer. When edited through this command, the file is checked for errors and only saved if there are none.

    crontab [path to file] can be used to specify a crontab stored in a file. Like crontab -e, this will only install the file if it is error free.

    Therefore, a script can either directly write cron tab files, or write them to a temporary file and load them with the crontab [path to temp file] command. Writing directly saves having to write a temporary file, but it also avoids the safety check.

提交回复
热议问题