bash, shutdown after script exits.

Hello community,

a small question in relation to bash, I would like my computer to shutdown after finishing a script.
Essentially something like this:

script.sh; sudo shutdown -hP now

The problem is, I would like to insert the root password at the time I am executing the above command, and not after the script exits.
Furthermore, I would prefer not running the script as root.

Thank you

Nikos78 wrote:
> Hello community,
>
>
> a small question in relation to bash, I would like my computer to
> shutdown after finishing a script.
> Essentially something like this:
>
> Code:
> --------------------
> script.sh; sudo shutdown -hP now
> --------------------
>
> The problem is, I would like to insert the root password at the time I
> am executing the above command, and not after the script exits.
> Furthermore, I would prefer not running the script as root.

I suppose the easiest solution would be to edit /etc/sudoers to allow
the user that runs the script to issue that shutdown command without
giving a password. Is that a solution that works for you?

If I can restrict the “no password requirement” to the shutdown command, I think it is a fair workaround. Any suggestions as to how I would be doing that?

Nikos78 wrote:
> djh-novell;2568001 Wrote:
>> Nikos78 wrote:
>>> Hello community,
>>>
>>>
>>> a small question in relation to bash, I would like my computer to
>>> shutdown after finishing a script.
>>> Essentially something like this:
>>>
>>> Code:
>>> --------------------
>>> script.sh; sudo shutdown -hP now
>>> --------------------
>>>
>>> The problem is, I would like to insert the root password at the time
>> I
>>> am executing the above command, and not after the script exits.
>>> Furthermore, I would prefer not running the script as root.
>> I suppose the easiest solution would be to edit /etc/sudoers to allow
>> the user that runs the script to issue that shutdown command without
>> giving a password. Is that a solution that works for you?
>
> If I can restrict the “no password requirement” to the shutdown
> command, I think it is a fair workaround. Any suggestions as to how I
> would be doing that?

man sudoers

So it seems this is what I will have to add to my sudoers file using visudo.

Nikos78 ALL=(ALL) NOPASSWD: /sbin/shutdown

Going to try that after work. Thank you!

Ok, let me correct that, as with the above code rooty powers seemed not to be restricted to /sbin/shutdown

Nikos78 ALL=NOPASSWD:/sbin/shutdown

On 2013-06-28 13:56, Nikos78 wrote:

>> Nikos78 ALL=NOPASSWD:/sbin/shutdown



Nikos78 machine_name = (root) NOPASSWD: /sbin/shutdown


Please use code tags for printouts and commands. Advanced forum editor,
‘#’ button. Posting in Code Tags - A Guide


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I am using INIT 0 to shutdown remotely or locally.

Remotely I type in my konsole, or ssh connection: init0 && exit

Locally you wont need the ‘&& exit’.

You can use this in bash scripting as well in other languages / scripts.

Hope this helpt.

On 2013-07-10 12:06, Marjon wrote:
>
> I am using INIT 0 to shutdown remotely or locally.

The problem in this thread is not the command to use to shutdown: it is
how to do it as plain user.


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

OOOwww, sorry! :stuck_out_tongue: :shame:

Maybe this helps. I’ve tried it, and should work.

https://wiki.archlinux.org/index.php/Allow_Users_to_Shutdown

And here is another possibility:

How to allow non-super users to shutdown computer in Linux - a great resource for How To’s from Wikia