The shutdown command works fine but cannot give a number of seconds before stopping: it is at least minutes. Regarding the password, shutdown the computer is an operation that only root can do (you can stop as normal user in gnome because gdm is run as root and if you log in normally then console you do a startx you cannot turn off the computer). It will therefore precede the command with sudo, but you can edit the file / etc / sudoers (with sudo visudo-f / etc / sudoers) to be able to run shutdown with no password. It will add two lines like this:
Code:
# Cmnd alias specification Cmnd_Alias ETEINDRE=/sbin/shutdown, /sbin/init, /sbin/halt, /sbin/poweroff # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL, NOPASSWD:ETEINDRE
Finally, if you want to do a script, here are some ideas: Launch the script, it checks if the file / tmp / foo exists. If NOT -> we created and we put the pid into the process. If YES -> the script has already been launched and should be read to kill the process whose pid is in the file. For the countdown, you can do:
Code:
i=0 while [ $i -lt $sec ] do sleep 1s echo Extinction dans $(( $sec - $i)) secondes done
edit: I find easier than the pid:
- If the file / tmp / foo does not exist it is created
- If it exists it is destroyed
- Before starting shutdown, if the file / tmp / foo shutdown is when you throw and if we do not start shutdown.
Bookmarks