LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   create user to shutdown system (https://www.linuxquestions.org/questions/linux-general-1/create-user-to-shutdown-system-848615/)

mah454 12-06-2010 04:34 AM

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 !:confused:

TB0ne 12-06-2010 07:49 AM

Quote:

Originally Posted by mah454 (Post 4182041)
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 !:confused:

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
.

chickenjoy 12-06-2010 08:36 AM

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

mah454 12-06-2010 09:29 AM

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 :


chickenjoy 12-06-2010 09:39 AM

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).

mah454 12-06-2010 09:48 AM

ooooooo !
Ok !
this script now work . :)
Thank you .

teethador 12-31-2010 03:37 AM

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.

teethador 12-31-2010 03:38 AM

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.

TB0ne 12-31-2010 09:12 AM

Quote:

Originally Posted by teethador (Post 4208524)
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.

teethador 01-02-2011 01:46 PM

Thanks and I won't again.


All times are GMT -5. The time now is 08:00 PM.