Guest User

Untitled

a guest
May 24th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. function manage_user()
  4. {
  5. user=$1
  6. password=$2
  7. shift; shift;
  8.  
  9. out=`ralsh user $user password='$password' ensure=present`
  10. echo $out | grep 'notice.*changed password'
  11. return $?
  12. }
  13.  
  14. user=$1
  15. password=$2
  16.  
  17. if [ -z $user ]
  18. then
  19. echo "What user?"
  20. exit 1
  21. fi
  22.  
  23. if [ -z $password ]
  24. then
  25. echo "What encrypted password?"
  26. exit 1
  27. fi
  28.  
  29. id $user >& /dev/null
  30.  
  31. case "$?" in
  32. 0)
  33. manage_user $user $password
  34. if [ $? -eq 0 ]
  35. then
  36. echo "Changed password for $user"
  37. exit 0
  38. else
  39. echo "Didn't change password for $user"
  40. exit 1
  41. fi
  42. ;;
  43. 1) echo "User doesn't exist!"; exit 1 ;;
  44. *) echo "There was a problem verifying user's existence!"; exit 1 ;;
  45. esac
  46.  
  47. exit 0
Add Comment
Please, Sign In to add comment