Skip to content

Instantly share code, notes, and snippets.

@aduzsardi
Last active August 13, 2017 07:07
Show Gist options
  • Save aduzsardi/5d11057eff53eab6c267c5e67fb46eea to your computer and use it in GitHub Desktop.
Save aduzsardi/5d11057eff53eab6c267c5e67fb46eea to your computer and use it in GitHub Desktop.
create home folders for ldap users in NFS export
#!/bin/bash
# Se foloseste in felul urmator
# - trebuie sa ai o lista cu useri in LDAP unul cate unul pe linie separata
# - rulezi scriptul './mkhomes.sh lista_useri.txt'
# Scriptul trebuie rulat pe un server integrat cu LDAP , pe CDN 99.99% .
if [ $# -ne 1 ];then
echo
echo -e "\t\t Usage: $0 users_file.txt"
echo -e "\t\t user_file must contain the users one per line"
echo
exit 1
fi
while read u; do
userdir=$(ldapsearch -x -LLL "(uid=$u)" homeDirectory | egrep -v "^dn:|^$" | awk '{print $2}' | sed s#nfs#tank/users#)
if [ ! -z "$userdir" ];then
echo "Creating home for: $u"
mkdir -vp ${userdir}
chown -v ${u}:root ${userdir}
chmod -v 700 ${userdir}
else
echo "Error: user '$u' not found in LDAP" >> ldap_mkhomes_err.log
fi
done < $1 | tee -a nfs_mkhomes_$(date +%d-%m-%Y).log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment