Skip to content

Instantly share code, notes, and snippets.

@tcooper
Created July 17, 2014 23:33
Show Gist options
  • Save tcooper/302c0ea743e32c496bde to your computer and use it in GitHub Desktop.
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
#!/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