Operating System - HP-UX
1830939 Members
2740 Online
110017 Solutions
New Discussion

delay individual crontabs

 
Mark Ellis
Advisor

delay individual crontabs

I would like to be able to stop an individual users crontab from time to time -- without effecting other crontabs. Is there a slick way to go about this? Why isn't there a "crontab -delay" swicth?

Thanks!!
8 REPLIES 8
Pete Randall
Outstanding Contributor

Re: delay individual crontabs

Mark,

I guess you could try editing, moving or renaming individual users crontabs in /var/spool/crontabs/.


Pete

Pete
Rodney Hills
Honored Contributor

Re: delay individual crontabs

The usual way to adjust crontab is to-
crontab -l >my.cron
vi my.cron
crontab
Each individual user has a seperate crontab file (As I guess from your description). If you do the following as root, you can deactivate one specific user-

echo "crontab -l >/tmp/joeuser.cron ; crontab
This will save the users current crontab then clear out the crontab.

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: delay individual crontabs

I don't know if this is slick enough to make you sweat Wesson Oil but here is one approach:

su - someuser
crontab -l > someuser.crontab # don't lose this file!!
crontab < /dev/null
exit


At this point, someuser's crontab is now empty.

To restore at some later time:
su - someuser
crontab < someuser.crontab
exit

If it ain't broke, I can fix that.
Mark Ellis
Advisor

Re: delay individual crontabs

I would like "root" intervention to be taken out of the loop and allow this user to stop their crontab jobs at any given time on their own.
A. Clay Stephenson
Acclaimed Contributor

Re: delay individual crontabs

As long as the user is a cron user (as specified in /var/adm/cron/at.allow) then he can manage his own crontab. You simply drop the su - someuser commands in my above responce. You could put together a script to do all of this for him, saving his cronjobs file in his home directory.
If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: delay individual crontabs

The same technique (crontab -l > somefile, etc) can work for the user as well. You could even script it for them. One script to set it aside, one to put it back.


Pete

Pete
Mark Ellis
Advisor

Re: delay individual crontabs

Thank you all!
Chris Wilshaw
Honored Contributor

Re: delay individual crontabs

The other option would be to build in the delay mechanism to the jobs they're running.

while [ -f /tmp/CRONLOCK ]
do
echo "Cron locked. Sleeping."
sleep 30
done

Then, when you create /tmp/CRONLOCK, the jobs will sleep until the file is removed.

if you need to lock cron on a user-by-user basis, use a file from CRONLOCK.