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

Posted on 2003-03-25
Medium Priority
Last Modified: 2013-12-06
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.

Question by:UnixScott
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 21

Accepted Solution

tfewster earned 300 total points
ID: 8203791
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.

Expert Comment

ID: 8203841
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.

Author Comment

ID: 8203906
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!


Expert Comment

ID: 8203909
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.]
LVL 21

Expert Comment

ID: 8205941
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.


Author Comment

ID: 8210120
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question