I have a list of jobs in the crontabs for user1, user2. I want to prevent the jobs of user2 from running.

I tried listing user2 in cron.deny, but that only prevents him from accessing his crontab. The jobs listed in user2's crontab still get executed.

How do I disable cron jobs for a specific user?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

Brute force!

crontab -u fred -e
%s/^/#/
:wq

There's probably a more elegant way to do it, but unless you are doing this all the time, use the hammer you have.

link|improve this answer
I was doing it the same way. Was wondering if cron should have this feature integrated. – NOLFXceptMe Jan 20 at 9:25
feedback

crontab -r username works on Solaris to remove the crontab for a given username.

If -r doesn't work for you, then try:

su username 'sh -c "crontab /dev/null"'

Quicker to type and easier to script than crontab -e.

link|improve this answer
The problem with this is that it destroys the user's information, which you probably shouldn't do unless you're dealing with a hostile user (and perhaps not even then). The other answer just comments out the user's crontab, which strikes me as a better idea. – Keith Thompson Feb 13 at 5:32
As @KeithThompson says, I do not want to erase the crontab for that user. I just want to disable it. The use case is such that I'd like to enable it later. – NOLFXceptMe Feb 13 at 20:51
feedback

Your Answer

 
or
required, but never shown

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