Labels

Arduino (1) Bugs (3) C (1) HTML (1) Install (3) Linux (27) Maths (1) Python (11) Raspberry Pi (4)

Wednesday, 22 February 2017

Check root at start of script


Some scripts need to be run as root and you may want to check at the start of that script that it is running as root. This can be done by checking the environment variable $EUID. This variable will hold the value 0 if it's being run as root.
#!/bin/bash
if [ "$EUID" -ne 0 ];then
echo "Please run this script as root"
exit 1
fi