editing crontab help

I'm using fedora 5 and sql 5.0. I'm trying to edit the crontab to perform automatic backups of my database. For some reason it isn't working. Here is what I have so far.

15 2 * * * /usr/bin/mysqldump -opt -all-databases u root -ppassword -h localhost /home/ruth/backup/alldb_`date`+%m-%d-%Y``.sql

Can anyone explain to me why this isn't working. I've looked in the crontab logs but it doesn't show anything.

Use single quotes around the date format instead of back ticks:

15 2 * * * /usr/bin/mysqldump -opt -all-databases u root -ppassword -h localhost /home/ruth/backup/alldb_`date '+%m-%d-%Y'`.sql

In addition to the type of quotes, the "%" character is special to cron (it means "newline"). All the "%" characters need quoting as "\%".

You will be better putting long commands into a script file and executing that from cron. This also gives you somewhere to set the environment for your commands.

Can you point me to a good reference that describes how to get scripts to work with cron. I haven't found one that works yet. I know you make a file usin vi editor but getting cron to execute it well thats a bit tricky.

Hello randerson21.

This below link is a par-for-the-course response :slight_smile:

If you have specific issues that are not addressed in the link, or any of the other information to which it refers, please post them here.

Regards.

I'm still trying to get the auto backup to work. I'm in the shell prompt and I've typed

crontab -e 11 05 * * * mysqldump -u ruth -ppassword -h localhost world > /home/ruth/backup/world_try

Unix keeps complaining out the options for password. It says invalid option --p usage error unrecognized option. What do I do about this? I tired the above options with crontab -e and it would also complain about the date. I like the idea of putting a date in my file name but can't get it to work so I've simplified it a little. Please help everthing I read and try does not work.

mysqldump -u sadmin -p pass21 Customers > custback.sql

why u dont put this in bash script and run it with debug option ( bash -x script.sh )?

One thing at a time. I tired putting it in a script that didn't work. So I'm trying to get this to work just to see if I'm even doing it right. When I get this to work I'll work on the script. There isn't a lot of information on how to do this. I'm new to unix.

The above command is wrong.
To start with it would help to know a bit about your environment.
What do you get for:

# Operating System
uname -a
# Are you root or a named user
who am i
# What Shell you are using
echo $SHELL
# What Editor will the "crontab -e" command use
echo $EDITOR
# What Editor might the "crontab -e" command use
echo $VISUAL
# Do we have permission to use the crontab command?
# If so, is there and existing crontab for this user and what is in it?
crontab -l

I installed linux myself, I'm logged on as root. My os is linux 2.6.15-1.2054.
When I tried echo $EDITOR and echo $VISUAL the result was blank. When I typed in the command crontab -l I got 16 4 * * * /etc/webmin/cron/tempdelete.pl which is going delete the webmin temp files. It didn't really show me the typical permissions.

Assuming you are trying to add a line to the existing root cron and that you are happy to run "mysqldump" as the user "root".

1) Review your proposed crontab entry after also reading the suggested instructions in post #2.
The environment under cron is quite different from the command line.
The proposed cron line will probably be best as a named script because you will invariably have to set
some environment variables before running "mysqldump"
(not least of which would be $PATH so you can find the program).

Though stating the obvious this cron will fire at 05:11 (early hours of the morning) 7 days a week.
11 05 * * * mysqldump -u ruth -ppassword -h localhost world > /home/ruth/backup/world_try

2) Set the environment variable "EDITOR" to your normal editor and export the variable.
# If your normal editor is "vi"
EDITOR="vi"
export EDITOR

3) Copy the root crontab in case or accident
crontab -l > /tmp/root_crontab_saved

4) Edit the crontab
crontab -e

In the editing session insert your new line into the crontab.
Whether you do this by typing it or by importing your existing file is up to you.
There will then be two distinct lines.
At the end of your editing session when you save the file the crontab will become active.

Reference: The instructions referred to in post #2 are quite good.