I have this script to shutdown my system after 30 seconds. I want to run this script by double clicking it (that option I changed in nautilus). This is the content of my script
#!/bin/bash
shutdown -h +30;
echo "succesfull"
read -p "Press any key to continue... " -n1 -s
to make sudo script executable without a password I followed this answer and I am able to execute this script from the terminal without using a password (sudo ~/test/test.sh
). The problem is when I double click the above script it's again asking for root privileges:
shutdown: Need to be root
successful
Press any key to continue...
What's the problem here?
You can make a conditional to relaunch the script as root if it's launched as a normal user.
To shutdown the computer:
Simplified version:
Very simplified version (not recommended):
To suspend the computer:
Simplified version:
Very simplified version:
Note:
$0
is a variable that holds the full path to the script.