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 12-06-2010, 04:34 AM   #1
mah454
Member
 
Registered: Oct 2009
Location: Iran
Distribution: Debian , Ubuntu , RHEL , CentOS , NetBill
Posts: 134

Rep: Reputation: 15
create user to shutdown system


Hello .
Excuse me for bad English !

I need create user .
when user login --> system go to shutdown .

I create this script :
Code:
### Shutdown Script ###
#!/bin/bash

echo "System Shutdown ..."
shutdown -h now
and make executable this script in /usr/local/sbin/sholt
Code:
-rwsr-xr-x. 1 root root 48 Dec  5 17:54 /usr/local/sbin/sholt
now i do make user with this shell :
Code:
useradd -s /usr/local/sbin/sholt sysoff
my passwd :
Code:
sysoff:x:501:501::/home/sysoff:/usr/local/sbin/sholt
but do not work !

Last edited by mah454; 12-06-2010 at 04:35 AM.
 
Old 12-06-2010, 07:49 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,695

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by mah454 View Post
Hello .
Excuse me for bad English !

I need create user .
when user login --> system go to shutdown .

I create this script :
Code:
### Shutdown Script ###
#!/bin/bash

echo "System Shutdown ..."
shutdown -h now
and make executable this script in /usr/local/sbin/sholt
Code:
-rwsr-xr-x. 1 root root 48 Dec  5 17:54 /usr/local/sbin/sholt
now i do make user with this shell :
Code:
useradd -s /usr/local/sbin/sholt sysoff
my passwd :
Code:
sysoff:x:501:501::/home/sysoff:/usr/local/sbin/sholt
but do not work !
Right...it won't because you don't have permissions to shut down the system, and because you haven't specified the path to the shutdown command. First, put the user you just created into the SUDO'ers file, and make sure it doesn't prompt for a password. Then, in your script, modify the shutdown line to read:
Code:
sudo /sbin/shutdown -h now
.
 
Old 12-06-2010, 08:36 AM   #3
chickenjoy
Member
 
Registered: Apr 2007
Distribution: centos,rhel, solaris
Posts: 239

Rep: Reputation: 30
1. add the user in the sudoers file to allow him to shutdown the machine which typically only super users can do.
Code:
# echo "sysoff ALL=NOPASSWD: /sbin/shutdown -h now" >> /etc/sudoers
2. now login as the user 'sysoff' and every time you want to shutdown the machine; execute the following command exactly:
Code:
$ sudo /sbin/shutdown -h now
 
Old 12-06-2010, 09:29 AM   #4
mah454
Member
 
Registered: Oct 2009
Location: Iran
Distribution: Debian , Ubuntu , RHEL , CentOS , NetBill
Posts: 134

Original Poster
Rep: Reputation: 15
thank you for answer .
I need auto shutdown system after login .
Code:
Login : sysoff
password : [Enter Password]
System Shutdown ... 
init: Need to be root

Login :
 
Old 12-06-2010, 09:39 AM   #5
chickenjoy
Member
 
Registered: Apr 2007
Distribution: centos,rhel, solaris
Posts: 239

Rep: Reputation: 30
3. login as sysoff and then run the following command:
Code:
$ echo "sudo /sbin/shutdown -h now" >> ~/.bash_profile
log-out and then try to log-in again as sysoff; the system will start the shutdown process. what this does is; it will run the command in step 2 automatically every time you start a login-shell (or login in layman's term).
 
Old 12-06-2010, 09:48 AM   #6
mah454
Member
 
Registered: Oct 2009
Location: Iran
Distribution: Debian , Ubuntu , RHEL , CentOS , NetBill
Posts: 134

Original Poster
Rep: Reputation: 15
ooooooo !
Ok !
this script now work .
Thank you .
 
Old 12-31-2010, 03:37 AM   #7
teethador
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
Good Morning:

This is exactly what I have for a shutdown script:


!#/bin/bash

sudo /sbin/shutdown -h now

Saved as Shutdown.sh

#whoami
root

#ls -l
-rwxr-xr-x 1 root root Shutdown.sh

#Shutdown.sh
bash: Shutdown.sh: command not found


What am I doing wrong?

Thank you in advance for the assistance.
 
Old 12-31-2010, 03:38 AM   #8
teethador
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
If I click the Shutdown.sh on the desktop it works. But if I run it in Bash it does not execute and errors out.

Thanks for the feedback.

Last edited by teethador; 12-31-2010 at 03:47 AM.
 
Old 12-31-2010, 09:12 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,695

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by teethador View Post
Good Morning:
This is exactly what I have for a shutdown script:


!#/bin/bash
sudo /sbin/shutdown -h now

Saved as Shutdown.sh

#whoami
root

#ls -l
-rwxr-xr-x 1 root root Shutdown.sh

#Shutdown.sh
bash: Shutdown.sh: command not found

What am I doing wrong?
Thank you in advance for the assistance.
The script isn't in your path, and you're not specifying it. Try "./Shutdown.sh", or "/some/path/to/Shutdown.sh".

Also, DON'T hijack someone elses thread with your question. Open your own thread for your own question.
 
Old 01-02-2011, 01:46 PM   #10
teethador
LQ Newbie
 
Registered: Dec 2010
Posts: 3

Rep: Reputation: 0
Thanks and I won't again.
 
  


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
how to create a shutdown login in RHEL4 ES visitnag Linux - Newbie 6 08-13-2009 02:59 AM
User shutdown - 'cp -i -p shutdown /usr/sbin/shutdown2 - why does this not work, can? mitchellray Linux - Desktop 4 03-20-2009 09:31 PM
User can shutdown system. swamprat Linux - Newbie 8 12-24-2007 12:50 PM
Can't "shutdown -a -r now" as a normal user, though shutdown.allow exists mnemonic Linux - Software 5 08-15-2005 06:49 PM
Samba: how to create a logon script file when i add a system user. heero82 Linux - Software 2 06-19-2003 08:29 PM

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

All times are GMT -5. The time now is 04:29 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