Let´s say i write cron files via script and modify them direct under
/var/spool/cron/crontabs/
. When using the command crontab -e
crontab checks the syntax when i exit the editor. Is there any way, to do the same check via script?
To submit a cron job, specify the crontab command with the -e flag. The crontab command invokes an editing session that allows you to create a crontab file. You create entries for each cron job in this file. Each entry must be in a form acceptable to the cron daemon.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .
Crontab with -e option does open your default editor with the current cron file and installs it after exiting.
First of all, save your actual cron file to be sure of not losing or breaking anything.
crontab -l > backup.cron
You can directly install a file that you have cooked:
crontab yourFile.text
Or use a pipe in a script:
#/bin/bash
Variable="your scheduled tasks"
echo $Variable | crontab
You will get the error messages in the case of bad formatting.
More info: man crontab
Use chkcrontab
:
pip3 install chkcrontab
chkcrontab /etc/cron.d/power-schedule
Checking correctness of /etc/cron.d/power-schedule
E: 15: 0 12 * foo * * root echo hi
e: FIELD_VALUE_ERROR: foo is not valid for field "month" (foo)
e: INVALID_USER: Invalid username "*"
E: There were 2 errors and 0 warnings.
Or try a shell script 48-verifycron
from Wicked Cool Shell Scripts, 2nd Edition, but it's not as good.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With