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

I need help with a question in Bash Shell Scripting The following changes need t

ID: 3715185 • Letter: I

Question

I need help with a question in Bash Shell Scripting

The following changes need to be made to the script provided:

1. accept a username as a command line argument

2. instead of displaying the account information for all acount, output only the information for this account

#! /bin/bash

#This script returns import information about all users on the system

for user in $(cut -d: -f1 /etc/passwd)

do

IFS=$' '

userinfo=$(grep $user: /etc/passwd)

comment=$(echo $userinfo | cut -d: -f5)

home=$(echo $userinfo | cut -d: -f6)

groups=$(groups $user | cut -d: -f2)

#Skip users that do not have '/home' in the path to their home directory

if [ $(echo "$home" | grep -v '/home/') ]

then

continue

fi

echo "Username: $user"

echo "User Info: $comment"

echo "Home Directory: $home"

echo "Groups: $groups"

echo "Disk usage: $(du -sh $home)"

last=$(last $user | head -1)

if [ $( echo $last | wc -c ) -gt 1 ]

then

echo "Last login: "

echo "$last"

else

echo "User has never logged in!"

fi

echo ""

echo "--"

echo ""

done

#! /bin/bash #This script returns import information about all users on the system for user in $(cut -d f1 /etc/passwd) userinfo-$(grep Suser: /etc/passwd) comment=$(echo $userinfo | cut -d: -f5) home $(echo $userinfo | cut d: -f6) groups-$(groups Suser | cut -d f2) #Skip users that do not have?home . in the path to their home directory if [ $(echo "$home" I grep-v·/home/.) ] then continue fi echo "Username: Suser" echo User Info: $comment" echo "Home Directory: $home echo Groups: Sgroups" echo "Disk usage: $(du -sh $home) last-$(last Suser head -1) if [ $ echo $last wc c) gt 1 ] then echo "Last login: " echo "slast" else echo "User has never logged in!" fi echo echo--* echo done

Explanation / Answer

NOTE: I have completed the program for your assignment. Please check and let me know if you have any questions. I will acknowledge back with a response within 24 hours. Thanks for your patience.

Please make the below changes in your code and it should work find. Let me know if you face any issues.

if [ $# -ne 1 ]

then   

        echo "Atleast one argument must be passed"                                                                      

        echo "Usage: $0 <username>"                                                                                     

        exit 1                                                                                                          

fi                                                                                                                      

                                                                                                                        

uname=$1

for user in $(cut -d: -f1 /etc/passwd|grep "$uname")   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote