Active Topics

 


Reply
Thread Tools
Posts: 9 | Thanked: 0 times | Joined on Jun 2008
#1
I made a script file called "rbt" which contains only 2 lines of code:
sudo gainroot
reboot

When I "sh rbt", it only executes the first line of code and stops with a "#". It does not run the second line.

What's wrong? Help please. Thanks.
 
Posts: 263 | Thanked: 679 times | Joined on Apr 2008 @ Lyon, France
#2
Hi,

The easiest way to see what's happening is to think in terms of PIDs.

In the shell (PID 124, let's say) you run
Code:
rbt
, which will launch a sub-shell (PID 128, say). That subshell will then be the context for running the script, and the first line will be run in it. That is:
Code:
sudo gainroot
This has for effect to start a root shell (PID 130).

The rest of the rbt script is now blocked, waiting for PID 130 to exit.

If your sudoers file is set up correctly (that is, you've given yourself permission to run all commands as root via sudo), then you can try running
Code:
sudo reboot
directly.

Dave.
 

The Following 2 Users Say Thank You to dneary For This Useful Post:
qwerty12's Avatar
Posts: 4,274 | Thanked: 5,358 times | Joined on Sep 2007 @ Looking at y'all and sighing
#3
Code:
#!/bin/sh
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
        exec sudo gainroot <<EOF
exec $0 $*
EOF
        exit $?
fi
#real script follows
reboot
Thanks to fanoush.

EDIT: It may just be easier to use this; which can be run as user:
Code:
dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.req_reboot

Last edited by qwerty12; 2008-06-27 at 09:05.
 

The Following User Says Thank You to qwerty12 For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 15:44.