program to read print who you are, based on your user account in/etc/passwd.

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2006
Posts: 18
Reputation: sharma_vivek82 is an unknown quantity at this point 
Solved Threads: 0
sharma_vivek82 sharma_vivek82 is offline Offline
Newbie Poster

program to read print who you are, based on your user account in/etc/passwd.

 
0
  #1
Apr 20th, 2006
  1. import posix
  2. import string
  3. uid = `posix.getuid()`
  4. passwd = open('/etc/passwd')
  5. for line in passwd.readlines():
  6. rec = string.splitfields(line, ':')
  7. if rec[2] == uid:
  8. print 'hello', rec[0],
  9. print 'mind if we call you bruce?'
  10. break
  11. else:
  12. print "I can't find you in /etc/passwd"
  13. :)
Last edited by alc6379; Apr 22nd, 2006 at 9:13 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,069
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 938
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: program to read print who you are, based on your user account in/etc/passwd.

 
0
  #2
Apr 20th, 2006
Indent it correctly, download posix and give it a try.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: program to read print who you are, based on your user account in/etc/passwd.

 
0
  #3
Apr 22nd, 2006
Looks like it should work, assuming you have posix there.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC