In some cases, when you create a cronjob using comma line or bash script instead of using a text editor. You got this error code: errors in crontab file, can’t install.
# command='@reboot cd /home/vlmcsd && sudo ./vlmcsd -R30d'
# echo '0 9 * * * $command' | crontab -
"-":1: bad day-of-month
errors in crontab file, can't install.
The output shows bad day of month, but as you can see, the below command contains valid of format for crontab. You can visit https://crontab.guru to creating and testing cron tab times.
command='@reboot cd /home/vlmcsd && sudo ./vlmcsd -R30d'
echo '0 4 * * * $command' | crontab -
In this example, I want to run that file at 04:00 every day.
The root cause of the issue is I used a single quote in the commands. So, to fix it, just simple replace single quote by double quote.
command="@reboot cd /home/vlmcsd && sudo ./vlmcsd -R30d"
echo "0 4 * * * $command" | crontab -
As you can see, the error was gone, and the job is create.
# crontab -l
0 4 * * * @reboot cd /home/vlmcsd && sudo ./vlmcsd -R30d
5/5 - (1 vote)