The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Crontab question

Discussion in 'General Discussion' started by golden_eyes, May 9, 2011.

  1. golden_eyes

    golden_eyes Well-Known Member

    Joined:
    Aug 9, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    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. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  3. golden_eyes

    golden_eyes Well-Known Member

    Joined:
    Aug 9, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    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. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    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.
     
  5. golden_eyes

    golden_eyes Well-Known Member

    Joined:
    Aug 9, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    yes, Thank you very much, this is what I was looking for..... :)

    Appreciated!
     
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    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.
     
  7. golden_eyes

    golden_eyes Well-Known Member

    Joined:
    Aug 9, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    Thank you man for your effort, already done. :)
     
Loading...

Share This Page