Guest User

Untitled

a guest
Mar 1st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/bin/bash
  2. GLOBALPASS=/etc/passwd
  3. LOCALPASS=/tank/shell01/root/etc/passwd
  4. NEW=1
  5.  
  6.  
  7.  
  8. declare -a varray
  9. for aline in `sort -t\: -k3 -n ${LOCALPASS} | cut -d\: -f 1,3,4,6,7`
  10. do
  11. varray=(`echo $aline | awk '{ split($0, ulist, ":"); for(i=1; i<=11; i++) printf ulist[i] " "; }'`)
  12.  
  13. aname=${varray[0]}
  14. auid=${varray[1]}
  15. agid=${varray[2]}
  16. ahd=${varray[3]}
  17. ashell=${varray[4]}
  18.  
  19. ggrep -i ^${aname}: ${GLOBALPASS} > /dev/null 2>&1
  20.  
  21. if [ $? -eq "$NEW" ] ; then # New User
  22. cut -d\: -f3 ${GLOBALPASS} | ggrep ^${auid}$ > /dev/null 2>&1
  23. if [ $? -eq "$NEW" ]; then #uid not in use, add em
  24. unset pline
  25. unset sline
  26. pline=${aname}:x:${auid}:65534::/:/bin/false
  27. sline=${aname}:*LK*:::::::
  28. echo -e "\r\nNew User: $aname"
  29. echo $pline
  30. echo $sline
  31. echo -n "Import user? [N/y]: "
  32. read response
  33. if ! test $response; then
  34. response="n"
  35. fi
  36. if ([ $response = "y" ] || [ $response = "Y" ]); then
  37. echo $pline >> /etc/passwd
  38. echo $sline >> /etc/shadow
  39. echo "ADDED"
  40. fi
  41.  
  42. fi
  43. fi
  44.  
  45. done
Add Comment
Please, Sign In to add comment