Computing.Net > Forums > Unix > print user info script

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

print user info script

Reply to Message Icon

Name: littlelisa
Date: December 9, 2005 at 17:58:38 Pacific
OS: xxx
CPU/Ram: xxx
Comment:

I need help creating a script that will print user info.

the script has to have:
- named "printpasswd"
- it must take 1 arguement from the command line. the argument will point to a file that follows the /etc/passwd format
- it will parse the file and output each user's information in the following format: user-name,uid,gid,home,shell and notes




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: December 9, 2005 at 21:35:39 Pacific
Reply:

What do you have so far? This looks like homework, but I'll give you a hint. This loop reads the /etc/passwd file and parses the seven fields:

#!/bin/ksh

while IFS=":" read f1 f2 f3 f4 f5 f6 f7
do
echo "$f1"
echo "$f2"
echo "$f3"
echo "$f4"
echo "$f5"
echo "$f6"
echo "$f7"
done < /etc/passwd



0

Response Number 2
Name: littlelisa
Date: December 11, 2005 at 10:03:43 Pacific
Reply:

Here's what I have so far, but I don't know if its correct.

#!/bin/sh

if [ $# != 1 ]; then
echo "Usage: printpasswd [file]"
exit
fi

cat $1 | awk '/^[^#]/{print $0}' |
while read Line
do
IFS=":"
read UserName Bleh Uid Gid Bleh2 Home Shell

printf "$UserName, $Uid, $Gid, $Home, $Shell\n"
done


0

Response Number 3
Name: WilliamRobertson
Date: December 11, 2005 at 15:46:42 Pacific
Reply:

You can do most of it with one line:

awk -F: '!/^ *#/ {print $1,$3,$4,$6,$7}' testpasswd

although if this is a shell exercise it won't be what they want.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Shell variables php and mail



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: print user info script

user cleanup script www.computing.net/answers/unix/user-cleanup-script/6973.html

ftp shell script skip login www.computing.net/answers/unix/ftp-shell-script-skip-login/4887.html

Change user in script www.computing.net/answers/unix/change-user-in-script/6574.html