# editing crontab help

**URL:** <https://community.unix.com/t/editing-crontab-help/272451>\
**Category:** Fedora\
**Created:** [August 30, 2010, 1:37pm UTC](https://community.unix.com/t/editing-crontab-help/272451 "2010-08-30T13:37:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![randerson21](https://community.unix.com/letter_avatar/randerson21/32/6_22734026db12803ebb3e059622ac3534.png) [@randerson21](https://community.unix.com/u/randerson21)\
**Post date:** [August 30, 2010, 1:37pm UTC](https://community.unix.com/t/editing-crontab-help/272451/1 "2010-08-30T13:37:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Franklin52](https://community.unix.com/user_avatar/community.unix.com/franklin52/32/500_2.png) [@Franklin52](https://community.unix.com/u/Franklin52)\
**Post date:** [August 30, 2010, 2:48pm UTC](https://community.unix.com/t/editing-crontab-help/272451/2 "2010-08-30T14:48:51Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_22734026db12803ebb3e059622ac3534.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [August 31, 2010, 9:58am UTC](https://community.unix.com/t/editing-crontab-help/272451/3 "2010-08-31T09:58:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![randerson21](https://community.unix.com/letter_avatar/randerson21/32/6_22734026db12803ebb3e059622ac3534.png) [@randerson21](https://community.unix.com/u/randerson21)\
**Post date:** [August 31, 2010, 1:10pm UTC](https://community.unix.com/t/editing-crontab-help/272451/4 "2010-08-31T13:10:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Scott](https://community.unix.com/letter_avatar/scott/32/6_22734026db12803ebb3e059622ac3534.png) [@Scott](https://community.unix.com/u/Scott)\
**Post date:** [August 31, 2010, 1:18pm UTC](https://community.unix.com/t/editing-crontab-help/272451/5 "2010-08-31T13:18:05Z")

</div>

> [@randerson21](#):
>
> 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 🙂

> **[cron and crontab](https://www.unix.com/answers-to-frequently-asked-questions/13527-cron-crontab.html)**
>
> We have hundreds of threads involving cron and crontab. Rather than creating a post with dozens of links, I thought I'd just write up a tutorial with | The UNIX and Linux Forums

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.

---

<div class="post-metadata">

**Author:** ![randerson21](https://community.unix.com/letter_avatar/randerson21/32/6_22734026db12803ebb3e059622ac3534.png) [@randerson21](https://community.unix.com/u/randerson21)\
**Post date:** [September 1, 2010, 2:07pm UTC](https://community.unix.com/t/editing-crontab-help/272451/6 "2010-09-01T14:07:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mrowcp](https://community.unix.com/letter_avatar/mrowcp/32/6_22734026db12803ebb3e059622ac3534.png) [@mrowcp](https://community.unix.com/u/mrowcp)\
**Post date:** [September 1, 2010, 9:14pm UTC](https://community.unix.com/t/editing-crontab-help/272451/7 "2010-09-01T21:14:04Z")

</div>

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 )?

---

<div class="post-metadata">

**Author:** ![randerson21](https://community.unix.com/letter_avatar/randerson21/32/6_22734026db12803ebb3e059622ac3534.png) [@randerson21](https://community.unix.com/u/randerson21)\
**Post date:** [September 7, 2010, 11:01am UTC](https://community.unix.com/t/editing-crontab-help/272451/8 "2010-09-07T11:01:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_22734026db12803ebb3e059622ac3534.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [September 7, 2010, 11:47am UTC](https://community.unix.com/t/editing-crontab-help/272451/9 "2010-09-07T11:47:40Z")

</div>

> [@](#):
>
> 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

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

```plaintext
# 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

```

---

<div class="post-metadata">

**Author:** ![randerson21](https://community.unix.com/letter_avatar/randerson21/32/6_22734026db12803ebb3e059622ac3534.png) [@randerson21](https://community.unix.com/u/randerson21)\
**Post date:** [September 7, 2010, 2:15pm UTC](https://community.unix.com/t/editing-crontab-help/272451/10 "2010-09-07T14:15:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_22734026db12803ebb3e059622ac3534.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [September 8, 2010, 7:03am UTC](https://community.unix.com/t/editing-crontab-help/272451/11 "2010-09-08T07:03:44Z")

</div>

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".

```nohighlight
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.
