Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron says "errors in crontab file, cannot install" [closed]

Tags:

linux

bash

cron

I'm attempting to execute the following series of commands to create backups of MySQL databases.

When I attempt to add the command to my crontab using crontab -e I get the error "errors in crontab file, cannot install" and asks me if I want to retry.

mkdir /home/mysql-backup/`date '+%m-%d-%Y'`; mysql -s -r -e 'show databases' | while read db; do mysqldump $db -r /home/mysql-backup/`date '+%m-%d-%Y'`/${db}.sql; done; rm -r -f `date --date="1 week ago" +%m-%d-%Y`; du -k |sort -n > output; mail -s "MySQL Backups" "[email protected]" < output

Is there anything I should be changing in this file? Or should I look into creating a script file and calling that from cron.

Thanks in advance for any assistance you can provide.

like image 378
Steven Sokulski Avatar asked Dec 13 '25 05:12

Steven Sokulski


1 Answers

If you gave that script to crontab -e of course it will disagree. A line in a crontab file should start with 5 fields indicating when you want the script to run, as can be read in crontab's manpage.

On the other hand, most Linux distros nowadays have preset facilities for things that should be executed hourly (/etc/cron.hourly), daily (/etc/cron.daily), etc. It's a whole lot easier to just put your script in a file in the appropriate directory and it will get executed in the selected time raster. An added advantage is that in these files you won't be forced to cram everything into one line.

like image 188
fvu Avatar answered Dec 14 '25 20:12

fvu