Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #set -x
- #Usage
- if [ $# -ne 1 ]
- then
- echo "Usage : createuser.sh [FILE]"
- exit 2
- fi
- #read file $1 and add users
- while IFS=: read user name password groupe ; do
- echo "Verify username : $user "
- verif=$(cut -d : -f1 < /etc/passwd | grep $user)
- if [ "$verif" != "$user" ]
- then
- #group GID
- gid=$(cat /etc/group | grep $groupe | cut -d : -f 3)
- #last userID, our user is : lastID+1
- lastID=$(tail -1 /etc/passwd | cut -d : -f 3)
- userID=$(($lastID+1))
- echo "$user's id is : $userID "
- #Creat user directory
- echo "Creating user directory"
- mkdir /home/$user
- #add user to /etc/passwd
- echo "Adding User to /etc/passwd"
- echo "$user::$userID:$gid:$name:/home/$user:/bin/bash >> /etc/passwd
- #add user to /etc/shadow
- # i have a question about the numbers in the syntax
- echo "$user::8678:3:120:7:30:9500: >> /etc/shadow
- #Creat password
- echo "$user:$password" | chpasswd -m
- #copy skel dir to home dir
- cp -r /etc/skel/ /home/$user
- #Set permissions
- chown -R $user /home/$user
- else
- echo "User alreay exists"
- exit 3
- fi
- done < $1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement