Rebooting cleanly from a program

Posted on 2003-03-28
Medium Priority
Last Modified: 2011-04-14
I have an application where if everything goes titsup.com i would like to restart the machine.

So far i have found the reboot(LINUX_REBOOT_CMD_RESTART) command, but this is like pressing the reset button, just an instant reset, witout unmounting or closing anything down first.
I've also tried the line system("/sbin/shutdown -a -r now") with the user entred into the shutdown.allow in the /etc/ directory but this doesn't work either in the program or from a terminal window, only if the terminal is switched to root.

Can anyone help with this?

Question by:P_Shep
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
  • 2
LVL 18

Accepted Solution

liddler earned 300 total points
ID: 8223981
What about installing sudo and using that to run the shutdown command?

Author Comment

ID: 8224203
hmm, good idea, but how do you get round the password?
LVL 18

Expert Comment

ID: 8224317
You can use the NOPASSWD tag in your sudoers file, something like
user ALL= NOPASSWD: /sbin/shutdown

Expert Comment

ID: 8227051
One way is to create a new user, give it a name something like "shutmedown" with a UID of zero (ie root) and no password. That user, instead of having /etc/bash as the shell, has /etc/shutmedown as the shell. Create a script /etc/shutmedown:


init 6

Make sure that the script is executable. Now all you have to do is:
su - shutmedown

and the machine runs the script as root and shuts down and reboots.

This idea is particularly useful with other flavours of Unix. For example if the script had init 5 on a Solaris box, anyone can shut the machine down and power it off by logging in as shutmedown.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

741 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