Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Linux script call account_list.sh that is going to print a summary of s

ID: 672681 • Letter: C

Question

Create a Linux script call account_list.sh that is going to print a summary of some account information on your system. This script is going to parse that file to find and print the usernames for all non-system accounts from the /etc/passwd file. In addition, if the account has a non-standard (i.e., non-bash) shell, then the script will mark that username with an asterisk. In particular, when you look at a line of /etc/passwd, there are seven colon-delimited fields. The first is the username, the third is the user ID, and the seventh is the shell for that user. Your script must ignore all system accounts, which are accounts that have a user ID of less than 1000. If the account has an ID of at least 1000, then you will print the username of that account. If the shell for that account is not /bin/bash, then also print an asterisk after the name to indicate that it is non-standard. Of course, you'll need to build in to the script to read from /etc/passwd with a while loop. Then you should be using awk to extract the appropriate fields from each line.Here is a hint:

while read line;  
do  
# use awk here   
done < /etc/passwd

Explanation / Answer

while read line;
do
id=`echo $line |cut -d: -f3`
if [ $id -ge 1000 ]
then
username=`echo $line| cut -d: -f1`
cat /etc/passwd |grep $username | awk -F':' '{print $1}'
fi
done</etc/passwd