Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've a lot of users in my server using exactly the same cron schedule and this is causing high server load. Can we prevent this?

For example, if there's x numbers of users that use the following cron schedule: 0 1 * * *, is it possible to prevent future users in using the same cron schedule?

share|improve this question
    
See also serverfault.com/questions/321840/… –  charlesbridge Mar 22 '13 at 11:28
add comment

3 Answers

You can assign cron scheduled per user account:

crontab -e -u user
share|improve this answer
1  
This doesn't prevent two users from using the same schedule. –  slhck Mar 22 '13 at 10:44
add comment

Why not simply write a script that compares all the user's cron files and moves them on if they conflict? if this is found in several crontabs 0 1 * * * for each conflict that exists change move the minutes along 5 1 * * * and 10 1 * * *. Then simply run this script in the root crontab so that it automatically changes user crontabs often.

If it is crucial that users' cron jobs run at the times they specified you will have to take a look at using PAM limits.

share|improve this answer
add comment

If your users simply intend to perform nightly tasks, a solution based on running their ~/nightly.sh might be simpler.

You would then run «/home/*/nightly.sh», one after another. Of course you would have to run each user's script with her own permissions and in a reasonable environment (cron does these things).

But it might be quite simple. For example:

for user in user0 user1 user2 user3 ... 
do 
   script=/home/$user/nightly.sh
   [ -x $script ] || continue 
   sudo -u $user  2>&1 | mail -s "nightly.sh" $user 
done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.