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?
I am trying to create a program that will set up a crontab to
Share
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