LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-08-2004, 07:17 AM   #1
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Rep: Reputation: 15
Menu for shuting down and rebooting


Hi,

I have two linux boxes (Red Hat 9.0 and Squid 2.5.STABLE1) running as proxys at 2 cyber cafes. Sometimes it is needed to reboot or shutdown the servers, and it is hard for someone that has little computer knowledge to login and reboot / shutdown the system manually.

I would like to create a menu instead of the server login or maybe create a user that logs into that menu instead of the regular prompt, so that anyone can reboot or shutdown the server if needed. I used to use them with DOS, but as i 'm new to the LINUX world i don't know where to start.

Anyone knows how can I create the menu, or where can i find infomation about that ?

Thx =)

Last edited by landuchi; 11-08-2004 at 08:28 AM.
 
Old 11-08-2004, 12:46 PM   #2
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
Just write a simple shell script

#!/bin/bash
cat <<EOF

1. reboot server
2. shutdown server
0. cancel

Select an option

EOF

read option

case $option in
"1") /sbin/reboot;;
"2") /sbin/shutdown now -i0;;
"0") exit;;
*) echo "That wasn't a choice" ;;

esac
=======================

There are probably a ga-zillion different scripts you could write. I am sure others will add somemore elaborate ones.

Of course the reboot and shutdown commands must be runnable by a regular user.
 
Old 11-08-2004, 01:15 PM   #3
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
Great ! , thats what im talking about =). Now, where do i place the code so that the user logs into the script, and can do nothing else but shut down, reboot, o log out.
 
Old 11-20-2004, 10:00 AM   #4
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
Could someone tell me what to do with the script ?
 
Old 11-20-2004, 10:08 AM   #5
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
write the script
make it executable
then,
either replace the user's shell in the /etc/passwd file with the full path to the script

user:x:500:500:user1:/home/user:/usr/bin/myscript

or, give the user a shell as normal and in their .bash_profile (if they are using bash) enter
exec /path-to-the-script

ie
exec /usr/bin/myscript
 
Old 11-20-2004, 10:56 AM   #6
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
I created a new user and modified the user's shell in /etc/passwd

Thank you amfoster, the menu is now working =)

How do i know if the user i created is able to reboot and shutdown ?

Using the menu would be the fastest way of checking, but the people using internet wouldn't be very happy .

Last edited by landuchi; 11-20-2004 at 11:07 AM.
 
Old 11-20-2004, 11:29 AM   #7
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
I think we are going to find is that the users are not allowed to run the shutdown command. You may have to set up the sudoers file and change the script commands to use the sudo command also.

Do you know how to set that up?

The other choice would be to leave the script as is, and set the suid bit on the /sbin/shutdown and reboot commands.

chmod 4755 /sbin/shutdown then any user can run the command.

It is quite possible that you do not need to restart the entire machine. Can't the squid daemon or whatever simply be restarted rather than the entire machine?
 
Old 11-20-2004, 12:24 PM   #8
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
I just want the user i created to be able to use the shutdown command and nothing else =).

The linux is a proxy in a cybercafe, the idea of the menu is to give the owner a easier way of rebooting / shuting down the machine.
 
Old 11-20-2004, 10:35 PM   #9
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
As I said, you can set the suid bit on the shutdown command so anyone can run it and use that menu, or create an entry for the user to use sudo.

Easiest is the suid bit

chmod 4755 /sbin/shutdown and the reboot command
 
Old 11-21-2004, 01:15 PM   #10
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
I rather not give anyone the power to shutdown or reboot the system. There has to be a way of giving only this user that power.

Could you explain the hard way :P , I 'm sorry to be so annoying =) and thanks again for your help !
 
Old 11-21-2004, 01:23 PM   #11
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
edit the file /etc/sudoers by typing visudo at the command line as root

in that file make an entry for the user I will call him joe

joe ALL=(ALL) NOPASSWD: /sbin/shutdown, /sbin/reboot

then save the file

Change the menu you have and at the place where it says /sbin/shutdown insert the word sudo

"1") sudo /sbin/shutdown now -i0 ;;
"2") sudo /sbin/reboot ;;



The sudo command allows another user to run whatever apps root designates as long as he types the word sudo in front of the command. By default he is prompted for his password. (His not roots) but with the line in the sudoers file that says NOPASSWD: he will not have to put in his password.


-Tony
 
Old 11-25-2004, 11:38 AM   #12
landuchi
Member
 
Registered: Oct 2004
Distribution: Debian, Ubuntu
Posts: 74

Original Poster
Rep: Reputation: 15
Thanks a lot for helping me, the menu works perfectly.

I really really really really really really apreciate your help.

L@nduch!
 
Old 11-26-2004, 09:44 AM   #13
amfoster
Member
 
Registered: Aug 2004
Distribution: debian, SuSE
Posts: 365

Rep: Reputation: 36
Great Glad it worked out for you.

-Tony-
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ACPI shuting down when should be waking up navarre9 Linux - General 1 12-25-2005 02:18 AM
Help with shuting down my Mandrake Comp EagleEye Linux - Newbie 1 07-30-2004 05:13 PM
Shuting down when you're not root. lugoteehalt Linux - General 9 10-22-2003 04:41 AM
problems shuting down highhighs Mandriva 9 09-19-2003 12:12 AM
Shuting Down Redhat 7 Rycat Linux - General 5 04-27-2001 06:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration