I have the following code for a bash script:
passfile=/etc/passwd
for i in `grep 2000 $passfile`
do
fullname=`echo $i | cut -d: -f5`
useracc=`echo $i | cut -d: -f1`
userid=`echo $i | cut -d: -f3`
lastcom=`last | grep $useracc | head -1 | cut -c40-55`
echo "Full Name: " $fullname "User Account: " $useracc "User ID: " $userid "Last time logged in: " $lastcom
done
Which then gives me the following output:
Full Name: Abel User Account: asanchez User ID: 1001 Last time logged in: Thu Feb 25 11:24
Full Name: User Account: Sanchez User ID: /bin/bash Last time logged in:
Full Name: Cody User Account: banegasc User ID: 1002 Last time logged in: Mon Feb 22 00:03
Full Name: B. User Account: B. User ID: B. Last time logged in:
Full Name: User Account: Banegas User ID: /bin/bash Last time logged in:
Full Name: Selayoa User Account: scloud User ID: 1003 Last time logged in: Thu Feb 25 05:16
Full Name: S. User Account: S. User ID: S. Last time logged in: Sun Feb 21 23:02
Full Name: User Account: Bayless User ID: /bin/bash Last time logged in:
...
And so on and so forth.
So somehow field #5 is getting cut up into pieces due to the spaces involved in the names, but I have no idea, nor can I find out how to suppress the chopping up of that field.
Anyone know how I could fix this so that the full names can come out only one time and completely then?
PS: This is my first post. If I somehow screwed up on the posting etiquette, then I'll learn. I swear!