Best place to add a cron job within exiting crontab...?

meredevelopment

Registered
Jul 24, 2013
4
0
1
cPanel Access Level
Root Administrator
Hi, I'm trying to add a very simple DB backup script (using mysqldump --all-databases) to a cron job.

I see that there is a crontab file already used for lots of cpanel stuff, which seems to be owned by root, although I haven't worked out it's location yet.

Would it be safe to add my script as a new entry to this existing crontab? If so, when I edit it with nano (sudo env EDITOR=nano crontab -e) I can make changes, but when I go to save it, it wants to save as a temp file.

I'm very open to suggestions here. I'm relatively new to *unix and whm/cpanel and I just want to run a .sh once a day, any way is fine.

Thanks!
Ben
 

meredevelopment

Registered
Jul 24, 2013
4
0
1
cPanel Access Level
Root Administrator
Doing a DB backup with crontab, advice please

Hi, I'm trying to add a very simple DB backup script (using mysqldump --all-databases) to a cron job.

I see that there is a crontab file already used for lots of cpanel stuff, which seems to be owned by root, although I haven't worked out it's location yet.

Would it be safe to add my script as a new entry to this existing crontab? If so, when I edit it with nano (sudo env EDITOR=nano crontab -e) I can make changes, but when I go to save it, it wants to save as a temp file.

I'm very open to suggestions here. I'm relatively new to *unix and whm/cpanel and I just want to run a .sh once a day, any way is fine.

Thanks!
Ben
 

JaredR.

Well-Known Member
Feb 25, 2010
1,834
23
143
Houston, TX
cPanel Access Level
Root Administrator
Please do not post the same question to more than one forum section. I have merged your two threads into a single one.

when I edit it with nano (sudo env EDITOR=nano crontab -e) I can make changes, but when I go to save it, it wants to save as a temp file.
That is the expected behavior. When you run the crontab command with the -e switch, it opens the actual cron file for the user (located in /var/spool/cron) with a temporary filename for editing, normally in /tmp. When you save the changes and exit the editor, crontab automatically copies the temporary file from /tmp to the correct location in /var/spool/cron. This is explained briefly on the crontab man (manual) page:

Code:
       -e     This option is used to edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.  [I]After you exit from the editor, the modified crontab will be installed automatically[/I].
You can read the crontab man page by typing man cron at any shell command prompt.
 

meredevelopment

Registered
Jul 24, 2013
4
0
1
cPanel Access Level
Root Administrator
Ok thanks Jared, the double post was a mistake (I'd not seen that it was a moderated forum and thought the post had failed).

Thanks for the crontab info. So I should be ok to add my own script entries to the existing crontab file I assume? Any idea if they will be removed if cPanel/WHM is updated?

Ben