Created
August 25, 2015 07:13
-
-
Save 0xPr0xy/7810f08ad1b2fda16246 to your computer and use it in GitHub Desktop.
check errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
check_errs() | |
{ | |
# Function. Parameter 1 is the return code | |
# Para. 2 is text to display on failure. | |
if [ "${1}" -ne "0" ]; then | |
echo "ERROR # ${1} : ${2}" | |
# as a bonus, make our script exit with the right error code. | |
exit ${1} | |
fi | |
} | |
grep "^${1}:" /etc/passwd > /dev/null 2>&1 | |
check_errs $? "User ${1} not found in /etc/passwd" | |
USERNAME=`grep "^${1}:" /etc/passwd|cut -d":" -f1` | |
check_errs $? "Cut returned an error" | |
echo "USERNAME: $USERNAME" | |
check_errs $? "echo returned an error - very strange!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment