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.

Thanks
Scott
UnixScottAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tfewsterCommented:
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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
biraCommented:
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.
0
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,
Scott
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

rob-gCommented:
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.]
0
tfewsterCommented:
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.

0
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.

Scott
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.