Skip to content

Instantly share code, notes, and snippets.

View matthisk's full-sized avatar

Matthisk Heimensen matthisk

View GitHub Profile
@matthisk
matthisk / root.sh
Created July 1, 2013 22:09
Check if the script is running as the root user
ROOT_UID=0; # Only users with $UID 0 have root privileges
E_NOTROOT=87; # Non-root exit error
# Run as root
if [ "$UID" -ne "$ROOT_UID" ]; then
echo "Must be root to run this script."
exit $E_NOTROOT;
fi
@matthisk
matthisk / args.sh
Last active December 19, 2015 05:29
This bash script checks if the correct amount of arguments are supplied
#!/bin/bash
# Read arguments
# Author: Matthisk Heimensen
NO_ARGS=0
E_OPTERROR=85
if [ $# -eq "$NO_ARGS" ]; then # Script invoked with no command-line args
echo "Usage: `basename $0` options (-upfh)"
exit $E_OPTERROR # Exit and explain usage