开发者

How to add a Crontab without user input?

I am trying to create a program that will set up a crontab to run a program that checks the server's health. Is there a way to create a new crontab without any user input? I've tried a bunch of ambitious things mostly consisting of something along the lines of $echo "* * * * * /example" >> ~/crontab when I run this code I get a permission denied error, even when running it under a sudo call. I know a 开发者_开发问答question similar to this has been asked on this website, but there was no functional answer. Is there a way to automate adding crontabs? Or is it necessary to use contab -e and add it via the text editor?


crontab is regular text file, so you can add entries like you tried. This is a permission issue. Either change crontab file permission or set caller script +s permission.

P.S. ~/crontab means file located in home directory. If you call as web user, home is located in /var/www


$ echo "* * * * * /example" > my-crontab
$ crontab my-crontab

Thanks to https://askubuntu.com/a/216711/911295

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜