remove_user 820 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. LOGIN=$1
  3. current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. ini="$current_dir/scripts.ini"
  5. ldap_password=$(awk '/ldap_password/ {print $2}' $ini)
  6. dc=$(awk '/dc/ {print $2}' $ini)
  7. cn="$(awk '/cn/ {print $2}' $ini),$dc"
  8. users_ou="$(awk '/users_ou/ {print $2}' $ini),$dc"
  9. ldiftmp="/tmp/ldapuserremove.ldif"
  10. ldiftemplate="$current_dir/user_delete.ldif"
  11. if [ ! -f $ldiftemplate ]
  12. then
  13. echo "Template file not found in $ldiftemplate"
  14. exit 0
  15. fi
  16. if [ -z "$LOGIN" ]
  17. then
  18. echo "empty username. usage: remove_user 'username'"
  19. exit 0
  20. fi
  21. TEXT=$(cat $ldiftemplate)
  22. TEXT=${TEXT//\{LOGIN\}/$LOGIN}
  23. TEXT=${TEXT//\{PEOPLE_OU\}/$users_ou}
  24. echo "$TEXT" > $ldiftmp
  25. ldapmodify -D $cn -w $ldap_password -f $ldiftmp > /dev/null 2>&1
  26. if [ $? -gt 0 ]
  27. then
  28. echo 'Error'
  29. else
  30. echo 'Success!'
  31. fi
  32. rm $ldiftmp