1 #!/bin/bash
2 #
3 # userlist.sh
4 #
5 PASSWORD_FILE=/etc/passwd
6 n=1 #User number
7
8 for name in $(awk 'BEGIN{FS=":"} {print $1}' < "$PASSWORD_FILE")
9 # Field Separator = :
10 # Print first name
11 # Get input from password file /etc/passwd
12 do
13 echo "USER #$n = $name"
14 n=$[ $n +1 ]
15 done
16
17 exit $?
Results:
$ ./userlist.sh|less
USER #1 = root
USER #2 = bin
USER #3 = daemon
USER #4 = adm
USER #5 = lp
USER #6 = sync
USER #7 = shutdown
...
USER #20 = pcap
...
No comments:
Post a Comment