|
Bug in shell script using awk to read /etc/passwd?In your book Wicked Cool Shell Scripts, on p. 115, Script #40 Reporting Disk Hogs, on the 8th line the second part of the line reads: awk -F: '$2 > 99 {print $1} ') I am very new to shell scripting, so I am probably just not understanding how this line should be interpreted. In my Linux class, I have been learning that in the /etc/passwed file the 1st field is username, the 2nd field is password (x), and the third field is the UID, so wouldn't the $2 above really be $3 so that the script would be checking to see if the UID field, which is field 3 is greater that 99, not the password field,which is field 2? Please let me know, since this is confusing to me. Thanks for your help. You're right. But you haven't noticed that this is part of a pipe in that particular script: for name in $(cut -d: -f1,3 /etc/passwd | awk -F: '$2 > 99 { print $1 }')
The cut just extracts the name and uid from the password file, at which point the second field *is* the UID, and this way we can use awk to only print the username of accounts with uid's greater than 99. Remember, here's a typical few lines from the Linux / Unix /etc/passwd file: coloradoport:*:1041:1041:coloradoportraits:/home/coloradoport:/sbin/nologin
shining-light:*:1042:1042:shining-light-books:/home/shining-light:/sbin/nologin startup101:*:1043:1043:startup101:/home/startup101:/sbin/nologin Of course, looking at it now, I don't know why I didn't just use: for name in $(awk -F: '$3 > 99 { print $1 }' /etc/passwd)
But that's another story. :-)
Categorized:
Shell Script Programming
(Article 7289,
Written by Dave Taylor)
Tagged: awk, login, scripting, shell script Previous: What is a "public terminal" when it comes to logging in to a Web site? Next: How do I add pictures to my MySpace blog entries? Subscribe!
alert('XSS BUG Ditemukan..') Posted by: coba at November 1, 2007 5:08 AMI have something to say, now that you mention it, but ...
I do have a comment, now that you mention it!
|
Recommended
Recent Entries
Search
I Need Help!
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and RSS Feeds Building Web Site Traffic Business and Management CGI Scripts and Web Site Programming Computer and Internet Basics d) None of the Above Facebook Help Google Plus Help HTML and CSS Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Mac OS X Help Pay Per Click (PPC) Advertising Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help WordPress Help |