Created
July 17, 2014 23:33
-
-
Save tcooper/302c0ea743e32c496bde to your computer and use it in GitHub Desktop.
Create a home directory for the specified user with values from /etc/passwd and contents of /etc/skel
This file contains 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
#!/bin/sh | |
/usr/bin/getent passwd $1 2>&1 > /dev/null | |
if [ $? -ne 0 ]; | |
then | |
echo "Invalid user" | |
exit 1 | |
fi | |
uid=`/usr/bin/getent passwd $1 | /bin/cut -d: -f3` | |
gid=`/usr/bin/getent passwd $1 | /bin/cut -d: -f4` | |
home=`/usr/bin/getent passwd $1 | /bin/cut -d: -f6` | |
if [ -d "${home}" ]; | |
then | |
echo "${home} exists" | |
exit 2 | |
else | |
/bin/mkdir -pv "${home}" | |
/bin/cp -rv /etc/skel/. ${home}/ | |
/bin/chown -Rv ${uid}.${gid} ${home} | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment