Guest User

Untitled

a guest
Jun 1st, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. With numbered IDs...
  2.  
  3. One-liner:
  4.  
  5. #!/bin/bash
  6. ls -ldn /home/* | while read a; do uid="$(echo $a | awk '{print $3}')"; gid="$(echo $a | awk '{print $4}')"; user="$(basename "$(echo $a | awk '{print $8}')")"; password=$(< /dev/urandom tr -dc A-Za-z0-9_ | head -c12); echo useradd -g $gid -u $uid -d /home/$user -p $password $user; FILE=users.txt; if [ -f $FILE ]; then echo $user:$password >> users.txt; else echo touch users.txt; fi; done
  7.  
  8.  
  9. Script:
  10.  
  11. #!/bin/bash
  12. ls -ldn /home/* | while read a
  13.        do
  14.                uid="$(echo $a | awk '{print $3}')"
  15.                gid="$(echo $a | awk '{print $4}')"
  16.                user="$(basename "$(echo $a | awk '{print $8}')")"
  17.                password=$(< /dev/urandom tr -dc A-Za-z0-9_ | head -c12)
  18.                echo useradd -g $gid -u $uid -d /home/$user -p $password $user
  19.                FILE=users.txt
  20.                if [ -f $FILE ];
  21.                then
  22.                echo $user:$password >> users.txt
  23.                else
  24.                echo touch users.txt
  25.                fi
  26.        done
  27.  
  28.  
  29. With named IDs...
  30.  
  31. One-liner:
  32.  
  33. ls -ldn /home/* | while read a; do uid="$(echo $a | awk '{print $3}')"; gid="$(echo $a | awk '{print $4}')"; user="$(basename "$(echo $a | awk '{print $8}')")"; password=$(< /dev/urandom tr -dc A-Za-z0-9_ | head -c12); echo useradd -G $gid -U $uid -d /home/$user -p $password $user; FILE=users.txt; if [ -f $FILE ]; then echo $user:$password >> users.txt; else echo touch users.txt; fi; done
  34.  
  35.  
  36. Script:
  37.  
  38. #!/bin/bash
  39. ls -ld /home/* | while read a
  40.        do
  41.                uid="$(echo $a | awk '{print $3}')"
  42.                gid="$(echo $a | awk '{print $4}')"
  43.                user="$(basename "$(echo $a | awk '{print $8}')")"
  44.                password=$(< /dev/urandom tr -dc A-Za-z0-9_ | head -c12)
  45.                echo useradd -G $gid -U $uid -d /home/$user -p $password $user
  46.                FILE=users.txt
  47.                if [ -f $FILE ];
  48.                then
  49.                echo $user:$password >> users.txt
  50.                else
  51.                echo touch users.txt
  52.                fi
  53.        done
Add Comment
Please, Sign In to add comment