Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

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

Discussion in 'General Discussion' started by meredevelopment, Sep 25, 2013.

  1. meredevelopment

    meredevelopment Registered

    Joined:
    Jul 24, 2013
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    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
     
  2. meredevelopment

    meredevelopment Registered

    Joined:
    Jul 24, 2013
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    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
     
  3. cPanelJared

    cPanelJared Technical Analyst

    Joined:
    Feb 25, 2010
    Messages:
    1,835
    Likes Received:
    21
    Trophy Points:
    143
    Location:
    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.

    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. meredevelopment

    meredevelopment Registered

    Joined:
    Jul 24, 2013
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    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
     
  5. cPanelJared

    cPanelJared Technical Analyst

    Joined:
    Feb 25, 2010
    Messages:
    1,835
    Likes Received:
    21
    Trophy Points:
    143
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    A cPanel update will not remove a cron job you add to root's jobs using the crontab command.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice