Use man 5 passwd~ for details about the ~/etc/passwd file Pretty print the file
ID: 3703712 • Letter: U
Question
Use man 5 passwd~ for details about the ~/etc/passwd file Pretty print the file and then print a report at the end. Your report should include: How many users total on the system - Which users are allowed to login (ook at the shell) Output: Username UID GID Home Directory Shell Notes /bin/bash sbin/nologin sbin/nologin /sbin/nologin /sbin/nologin bin/sync /sbin/shutdown /sbin/halt /sbin/notogin /sbin/notogin /sbin/notogin /sbin/nologin sbin/nologin sbin/nologin /sbin/notogin /sbin/nologin /sbin/nologin 0 0 /root bin 1 1/bin bin 22 /sbin 3 4 /var/adm 4 7 /var/spoot/lpd 5 0 /sbin 6 /sbin sync shutdown halt mail operator shutdowr halt mait operator games FTP User 7 /sbin 8 12 /var/spool/mail 11 /root 12 100 /usr/games 14 50 /var/ftp ftp 192 192 81 81 / systend Network Managenent Systen nessage bus User for polkitd Account used by the trousers package to sandbox the tesd daemon systemd-network polkitd tss postfix chrony sshd student 99 997/ 59 59 /dev/null 89 89 /var/spool/postfix /sbin/nologin sbin/nologin /sbin/nologin /bin/bash /bin/false sbin/nologin 998 996 /var/lib/chrony Privilege-separated SSH Student User 74 74 /var/empty/sshd 1000 1068 /home/student 997 1 /var/run/vboxadd 996 994 /etc/unbound Unbound DNS resolver There are 23 users on this system The following users can login: shutdown, halt, vboxadd, student, sync, root,Explanation / Answer
Solution : Following script will do all the work :-
#!/bin/bash
#report.sh will pretty print the file, count users and list users allowed to login
awk -F: 'BEGIN{printf("%s %15s %10s %20s %20s %20s " ,"Username", "UID", "GID", "Home Directory", "Shell", "Notes")} BEGIN{printf "---------------------------------------------------------------------------------------------------------- "} { printf "%-20s %-10s %-10s %-28s %-20s %s ",$1,$3,$4,$6,$7,$5}' /etc/passwd
printf " "
awk 'END{print "There are " FNR " users on this system."}' /etc/passwd
printf " "
grep -v '/sbin/nologin' /etc/passwd | awk -F: 'BEGIN {print "The following users can login: "}{print $1}'
##################################
Output :
ubuntu@ubuntu:~$ ./report.sh
Username UID GID Home Directory Shell Notes
----------------------------------------------------------------------------------------------------------
root 0 0 /root /bin/bash root
daemon 1 1 /usr/sbin /usr/sbin/nologin daemon
bin 2 2 /bin /usr/sbin/nologin bin
sys 3 3 /dev /usr/sbin/nologin sys
sync 4 65534 /bin /bin/sync sync
games 5 60 /usr/games /usr/sbin/nologin games
..................................................
.................................................
There are 43 users on this system
The following users can login:
root
sync
systemd-timesync
systemd-network
...............................................
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.