daily pastebin goal
63%
SHARE
TWEET

Add users

a guest Oct 12th, 2017 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !/bin/bash
  2. userfile="xx.txt"
  3. IFS=$'\n'
  4. if [ ! -f "$userfile" ]
  5. then
  6.   echo "File does not exist. Specify a valid file and try again. "
  7.   exit
  8. fi
  9. groups=(`cut -f 4 "$userfile" | sed 's/ //'`)
  10. fullnames=(`cut -f 1 "$userfile" | sed 's/,//' | sed 's/"//g'`)
  11. username1=(`cut -f 1 "$userfile" |sed 's/,//' | sed 's/"//' | tr [A-Z] [a-z] | awk '{print substr($2,1,1) substr($3,1,1) substr($1,1,1)}'`)
  12. username2=(`cut -f 4 "$userfile" | tr [A-Z] [a-z] | awk '{print substr($1,1,1)}'`)
  13. i=0
  14. n=${#username1[@]}
  15. for (( q=0; q<n; q++ ))
  16. do
  17. usernames[$q]=${username1[$q]}"${username2[$q]}"
  18. done
  19. declare -a usernames
  20. x=0
  21. created=0
  22. for user in ${usernames[*]}
  23. do
  24. adduser -c ${fullnames[$x]} -p 123456789 -f 15 -m -d /home/${groups[$x]}/$user -K LOGIN_RETRIES=3 -K PASS_MAX_DAYS=30 -K PASS_WARN_AGE=3 -N -s /bin/bash $user 2> /dev/null
  25. usermod -g ${groups[$x]} $user
  26. chage -d 0 $user
  27.   let created=$created+1
  28. x=$x+1
  29. echo -e "User $user created    "
  30. done
  31. echo "$created Users created"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top