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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
