Automatically re-start script as root
If you use sudo you can automatically re-start scripts that need to be run as root by adding a check at the beginning of the script and executing sudo if the script is not running as root:
if [[ $UID -ne 0 ]]; then sudo -p 'Restarting as root, password: ' bash $0 "$@" exit $? fi
The inclusion of "bash" in the sudo command is to avoid problems if the script does not have its execute bit set. The "exit $?" causes the shell to exit with the status from the script instance that sudo runs.
Mitch Frazier is an Associate Editor for Linux Journal.
|openHAB||Apr 24, 2017|
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
|CodeLathe's Tonido Personal Cloud||Apr 19, 2017|
|Wrapping Up the Mars Lander||Apr 18, 2017|
|MultiTaction's MT Canvus-Connect||Apr 17, 2017|
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- Simple Server Hardening
- Understanding Firewalld in Multi-Zone Configurations
- Buddy Platform Limited's Parse on Buddy Service
- Linux Journal February 2017
- Gordon H. Williams' Making Things Smart (Maker Media, Inc.)
- A Switch for Your RPi
- Non-Linux FOSS: Control Web-Based Music!