Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Shutting off cron for a particular user - but only for a certain time period

Is there a way to turn off cron for a particular user for just a certain period of time?  I know that I could probably run a crontab -r to delete the current crontab, but then I would have to re-enter the commands.  I don't want cron itself stopped, just for one user, and only for a 4 hour time-period when we have to do some maintenance work.

1 Solution
crontab -l > cron.save, then crontab -r, then crontab < cron.save when finished...

Putting their username in /usr/lib/cron/cron.deny just stops them editing their crontab file - I'm not sure if it will disable their existing cron jobs.
There´s a file named /var/adm/cron/cron.deny ( in AIX )
 or /var/spool/cron/deny  (in LINUX ) , i don´t know
 about other Unix where it is.
 You can can deny someone to use crontab by editing it and
 placing the user name.
UnixScottAuthor Commented:
I know that I can save the crontab (crontab -l ...) as tfewster suggests, but I was wondering if there was another way of doing it.  And cleaner way of simply turning off cron (just for one user) and then turn it back on.

As for the cron.deny, my understanding is that will only stop the user from running crontab, but it won't stop the current crontab from executing.  If I am mistaken, maybe someone will correct me.

Thanks for the answers so far,
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

First backup you crontab entries using
  crontab -l user > crontab_user.backup

Turn off all crontab jobs by editing the crontab entry using piped 'ex' commands to add '#' as 1st char on each line.
  EDITOR=ex; export EDITOR;
  echo "%s/^/#/g\nx\n" | crontab -e user

To restore your backup (turn on all the cron jobs)
  EDITOR=ex; export EDITOR;
  echo "%d\nr crontab_user.backup\nx\n" | crontab -e user

[the above 'ex' commands are 1) delete all lines, 2) read from backup file, 3) write then exit.]
Scott, which Unix do you use? Some variants may have the functionality you want (But this would be a function of `cron` rather than the `crontab` command).

man cron (HP-UX):
cron establishes a schedule for crontab files ... when it is notified by ... crontab that a (crontab) file has been added, deleted, or modified.

I.e. on HP-UX cron does not check cron.deny (as you had already figured out) - So I would have to do the save/delete/recreate method.

UnixScottAuthor Commented:
tfewster - I'm using HP-UX.

Yes, on HP-UX the cron.deny entry will only stop a user from executing the crontab function, but it will not stop cron from executing any of the commands in an already existing "crontab" file.

I had already tested the save/delete/restore method before I posted here, but it just doesn't seem very clean to me.  I was hoping that there would have been a flag or semaphore or something that could be set to do what I needed.  But it doesn't look like that's the case.

I will give it another day to see if anyone can come up with a different method.  If not, then it will be save/delete/restore method.

Rob-g : Thanks for the alternate method, I tried it and it works find.  It's basically a different way of doing the same thing.  Save the crontab, comment out the entries (instead of deleting the file), then restore the crontab from the backup.  If I can't find another method, then I will simply use the crontab -r to delete the crontab file, rather than changing the EDITOR variable, and piping in the substitute command through crontab.  But thanks anyway.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now