Skip to content

Instantly share code, notes, and snippets.

@ChatchaiJ
Created September 4, 2020 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChatchaiJ/0087e0bfc28fe2e05f2c56c2473c1b21 to your computer and use it in GitHub Desktop.
Save ChatchaiJ/0087e0bfc28fe2e05f2c56c2473c1b21 to your computer and use it in GitHub Desktop.
#!/bin/sh
[ "`id -u`" != 0 ] && echo "Must be root to run this script" && exit -1
[ -z "$2" -o "$3" ] && echo "Usage: $0 user directory" && exit -1
USER="$1"
DIR="$2"
id "$USER" >& /dev/null || {
echo "User '$USER' not exist";
exit -1;
}
[ ! -d "$DIR" ] && echo "Directory '$DIR' not exist" && exit -1
sudo -u "$USER" test -d "${DIR}/."
if [ "$?" != 0 ]; then
echo "FAILED: $USER -> $DIR"
exit 1
else
echo "OK: $USER -> $DIR"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment