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?
5 Answers
Brute force!
crontab -u fred -e
%s/^/#/
:wqThere's probably a more elegant way to do it, but unless you are doing this all the time, use the hammer you have.
3The easiest way to disable the crontab for a specific user is to locate her crontab and rename it. The Debian man page for cron says:
cron searches its spool area (/var/spool/cron/crontabs) for crontab
files (which are named after accounts in /etc/passwd); crontabs found
are loaded into memory.So just rename the file to something that is not in the passwd, usually by giving it a suffix like disabled, offline, dead or similar.
mv -vi /var/spool/cron/crontabs/user2 /var/spool/cron/crontabs/user2.disabledOn Debian (and related systems like Ubuntu) this produces the following entry in /var/log/syslog:
(user2.disabled) ORPHAN (no passwd entry)Make sure to also add user2 to the file /etc/cron.deny, otherwise the user will be able to create a new crontab for herself.
Re-enable the user's crontab by deleting the entry from /etc/cron.deny and renaming her crontab:
mv -vi /var/spool/cron/crontabs/user2.disabled /var/spool/cron/crontabs/user2 Delete /var/spool/cron/user1 or user2 ? and you also want to add these user names to /etc/cron.deny otherwise they can add those cron jobs back
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.
If you want to block the crontab job for a particular user make sure that your logged in with root user,root user only have access for crontab files. 1.Then go to the dir /etc/cron.d in this directory you can see that cron.deny file,make an enter of particular user name which user want to block by using vi editor or orther.
1