Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    79

    Question Crontab question

    hey, how to update the crontab for all accounts at the same time?

    I have placed a file in the www folder for all accounts, and I must add the /home/account/www/cron.php for accounts, instead of crontab -u useraccount -e and add the line, is there any way to append all crontab and add the lines?

  2. #2
    cPanel Staff cPanelMichael's Avatar
    Join Date
    Apr 2011
    Posts
    1,346
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Crontab question

    Hello

    There are no native options to add a specific cron job to multiple accounts at once, however you can find the cron files for all accounts in the following directory:

    Code:
    /var/spool/cron/
    It's likely a bash command could be used to modify multiple files within the above directory in order to add a new line to each file.

    Thank you.
    cPResources: Support Options - Submit a ticket here - Additional Support Options - Forums Search - Mailing Lists - Documentation - Migration Services
    -- cPanelMichael - Migration Specialist, Technical Analyst, cPanel Technical Support

  3. #3
    Member
    Join Date
    Aug 2010
    Posts
    79

    Default Re: Crontab question

    Okay, so is it possible to build a script to create the files contain the cron command and place them in the /var/spool/cron/ ?

    Waiting your reply please..

    Thanks,

  4. #4
    cPanel Staff cPanelMichael's Avatar
    Join Date
    Apr 2011
    Posts
    1,346
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Crontab question

    Hello

    Yes, it's possible to use a custom bash command to create multiple files in a specific directory, and to add a new line to multiple files. Keep in mind when creating those scripts or commands, you should ensure the cron entries are not added to the system cron files (e.g. root, mailman).

    Thank you.
    cPResources: Support Options - Submit a ticket here - Additional Support Options - Forums Search - Mailing Lists - Documentation - Migration Services
    -- cPanelMichael - Migration Specialist, Technical Analyst, cPanel Technical Support

  5. #5
    Member
    Join Date
    Aug 2010
    Posts
    79

    Default Re: Crontab question

    yes, Thank you very much, this is what I was looking for.....

    Appreciated!

  6. #6
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

    Default Re: Crontab question

    I did want to show a method to do this, but you'd need to copy /var/spool/cron before doing so (in case anything didn't properly process):

    Code:
    cp -R /var/spool/cron /var/spool/cron.bak110510
    for i in `ls /var/cpanel/users/`;do echo "0 3 * * * /home/$i/public_html/cron.php" >> /var/spool/cron/$i;done
    When you run the above command, replace the 0 3 * * * with the actual interval for the cron, since this is 3:00am server time every day for my example. Replace /home/$i/public_html/cron.php with the path to the file (please note it is public_html that is the true path rather than www as www is a symlink only to public_html). The $i portion should not be changed in that path as it represents the username that is pulled from /var/cpanel/users/ list in the for i in `ls /var/cpanel/users` section of the command.

    Please note that the best benefit of doing it this way, if the crontab files did not already exist for the user, this command creates those files for every user found in /var/cpanel/users location. Please ensure that root does not have an existing file in /var/cpanel/users/ location, since it will then add contents to the root crontab.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  7. #7
    Member
    Join Date
    Aug 2010
    Posts
    79

    Default Re: Crontab question

    Quote Originally Posted by cPanelTristan View Post
    I did want to show a method to do this, but you'd need to copy /var/spool/cron before doing so (in case anything didn't properly process):

    Code:
    cp -R /var/spool/cron /var/spool/cron.bak110510
    for i in `ls /var/cpanel/users/`;do echo "0 3 * * * /home/$i/public_html/cron.php" >> /var/spool/cron/$i;done
    When you run the above command, replace the 0 3 * * * with the actual interval for the cron, since this is 3:00am server time every day for my example. Replace /home/$i/public_html/cron.php with the path to the file (please note it is public_html that is the true path rather than www as www is a symlink only to public_html). The $i portion should not be changed in that path as it represents the username that is pulled from /var/cpanel/users/ list in the for i in `ls /var/cpanel/users` section of the command.

    Please note that the best benefit of doing it this way, if the crontab files did not already exist for the user, this command creates those files for every user found in /var/cpanel/users location. Please ensure that root does not have an existing file in /var/cpanel/users/ location, since it will then add contents to the root crontab.
    Thank you man for your effort, already done.

Similar Threads & Tags
Similar threads

  1. Different Crontab? “crontab-and” and “/ etc/crontab”
    By Divino in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 09-14-2007, 06:04 AM
  2. Question - Crontab in my server (Curiosity)
    By hbhb in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 07-07-2007, 03:41 AM
  3. /etc/crontab not used
    By danf in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 07-02-2007, 10:29 PM
  4. crontab... really quick easy question
    By Diatone in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-03-2004, 06:22 PM
  5. Crontab question
    By stathis in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 10-29-2003, 01:30 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube