maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Newbie (https://talk.maemo.org/forumdisplay.php?f=26)
-   -   question about script (https://talk.maemo.org/showthread.php?t=21346)

jettt 2008-06-27 02:30

question about script
 
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.

dneary 2008-06-27 07:57

Re: question about script
 
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.

qwerty12 2008-06-27 08:38

Re: question about script
 
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


All times are GMT. The time now is 07:19.

vBulletin® Version 3.8.8