Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. #set -x
  3.  
  4. #Usage
  5. if [ $# -ne 1 ]
  6. then
  7. echo "Usage : createuser.sh [FILE]"
  8. exit 2
  9. fi
  10.  
  11. #read file $1 and add users
  12. while IFS=: read user name password groupe ; do
  13. echo "Verify username : $user "
  14. verif=$(cut -d : -f1 < /etc/passwd | grep $user)
  15. if [ "$verif" != "$user" ]
  16. then
  17. #group GID
  18. gid=$(cat /etc/group | grep $groupe | cut -d : -f 3)
  19. #last userID, our user is : lastID+1
  20. lastID=$(tail -1 /etc/passwd | cut -d : -f 3)
  21. userID=$(($lastID+1))
  22. echo "$user's id is : $userID "
  23. #Creat user directory
  24. echo "Creating user directory"
  25. mkdir /home/$user
  26. #add user to /etc/passwd
  27. echo "Adding User to /etc/passwd"
  28. echo "$user::$userID:$gid:$name:/home/$user:/bin/bash >> /etc/passwd
  29. #add user to /etc/shadow
  30. # i have a question about the numbers in the syntax
  31. echo "$user::8678:3:120:7:30:9500: >> /etc/shadow
  32. #Creat password
  33. echo "$user:$password" | chpasswd -m
  34. #copy skel dir to home dir
  35. cp -r /etc/skel/ /home/$user
  36. #Set permissions
  37. chown -R $user /home/$user
  38. else
  39. echo "User alreay exists"
  40. exit 3
  41. fi
  42. done < $1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement