Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

What is the simplest way to disable or temporarily suspend reboot/shutdown when an important process is running? The process takes too long to finish and cannot be paused/resumed so I like to avoid shutting down the pc while it is running. It is run from cron so unless I manually check for running processes, I wouldn't know that it is running. Thanks.

share|improve this question
5  
Possible duplicate: SO: Temporarily prevent linux from shutting down, the answers hint on the various levels on which this can be done, i.e. shell scripts or the desktop environment's power management. –  sr_ Mar 19 '12 at 9:07
    
I don't think that answer is specific enough without an either explanation of runlevels or link to explanation. It's not in the U&L SE. May I ask which distro and version you're using? –  bdowning Mar 19 '12 at 22:13
    
Rather than modifying the shutdown procedure, write a wrapper so the job indicates its finished, either mail or touch a file. Test for job completion, then run shutdown. (cron mails the output of its jobs to owner, but that can be tweaked). –  bdowning Mar 22 '12 at 10:53

5 Answers 5

up vote 0 down vote accepted

Run which shutdown to see where the path to the shutdown program is. You can rename the file, although I recommend against it.

Another (safer) method. Use an alias: alias shutdown=' ' Something like this is more reversible. If you're trying to prevent shutdown from all users, add the alias globally.

share|improve this answer
    
I'm thinking of using an alias, now I just have to write my script. Thanks! –  zang3tsu Mar 23 '12 at 7:07
    
What about other commands such as halt or poweroff. Would you need to create alias' / rename them too? –  mintyfreshpenguin Aug 25 at 18:43

I wanted to prevent a local user to shutdown a laptop during an upgrade. Disabling the input device was the best way to go. For me it was sufficient to disable the mouse, but the keyboard can be disabled as well.

Of course there's a drawback, the computer can't be used during this period.

Disable Keyboard & Mouse input on unix (under X)

share|improve this answer

shutdown is technically an application too, which you can remove. Run which shutdown. which is a command which shows you the path of an application. In my case the output is /sbin/shutdown. It's a file so you can just do rm shutdown. Or if you want to disable it temporarily copy it, change the name and remove the original file.

You must have the sufficient permissions if you want to do rm shutdown. It's read-only, hence why you may get an error. Try removing it as root or if necessary try using the command rm -rf shutdown.

Good luck!

share|improve this answer
1  
Why the -r flag? You wont need it for one file, and if you mistype something, disaster ensues. –  MadTux Aug 25 at 19:56

Disable the "shutdown/reboot/poweroff/halt/hostname" like commands in mission critical servers

chmod 0 /sbin/shutdown

then if you need to use it, chmod it back to chmod 0755.

share|improve this answer

I would disable the command in the /etc/sudoers file so that only root can execute it.

in /etc/sudoers

# Cmnd alias specification
Cmnd_Alias     SHUTDOWN = /sbin/shutdown

# User privilege specification
root    ALL=(ALL:ALL) ALL
vmule   ALL=(ALL:ALL) ALL, !SHUTDOWN

and when I try to run the command:

vmule@debian:~$ sudo /sbin/shutdown  -r now
Sorry, user vmule is not allowed to execute '/sbin/shutdown -r now' as root on debian.vm
share|improve this answer
    
can you elaborate your answer ? shutdown may not be explicitly specify in /etc/sudoers. –  Archemar Oct 17 at 9:21
    
Sure, I edited the answer with a better explanation. Cheers –  vmule Oct 17 at 9:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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