Register
It is currently Sat Dec 20, 2014 10:08 am

Mac User Name Question


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Mon Apr 12, 2010 9:15 am   

Joined: Mon Apr 12, 2010 9:07 am
Posts: 5
Hi All:

I am puzzled by a task that I am trying to complete and have searched and searched for some sort of resolve - with no luck. I decided I would come and ask the experts! I am working in Mac 10.5.8 and am looking for a way to echo the account user name. I have successfully echoed the long name and short name of the account but not the user name. If you go to Accounts under system preferences - you will notice that the User Name can be different from the short name and the long name. I would also like to be able to change this user name from the command line if possible - as i don't think it will affect permissions or anything like that because it is separate from the long name, short name, and user home. Any help would be greatly appreciated. Thanks in advance!

D


Top
 Profile  
 PostPosted: Mon Apr 12, 2010 11:14 am   

Joined: Mon Apr 12, 2010 9:07 am
Posts: 5
After more looking around - I may have been wrong in my description of the problem. I am not sure if the User Name and Long User Name are the same. I am attaching a screen shot of what i would like to echo/change from terminal.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 PostPosted: Mon Apr 12, 2010 1:17 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
This is not yet a bash problem ;), and I don't know mac
As a Debian GNU/Linux user, I only know login and full_name :(

Do you have finger, and chfn ?


Top
 Profile  
 PostPosted: Tue Apr 13, 2010 5:59 am   

Joined: Mon Apr 12, 2010 9:07 am
Posts: 5
Hello and thanks for the reply! I know this seems more like a mac thing (which it probably is) - but those forums I ask on - they always seem to say ask BASH scripting guys. :) Both the finger and chfn. I just did a man page on chfn and looks like it might do just that. I will let you know what I figure out and if you beat me to it - thanks! I would like to be able to do it in bash as I have a script that will change all the information at first log in from a database so I don't have to do it all manually and I couldn't seem to find where I could change this through bash. Thanks again!


Top
 Profile  
 PostPosted: Tue Apr 13, 2010 6:15 am   

Joined: Mon Apr 12, 2010 9:07 am
Posts: 5
So you were right. That is exactly the command in which I should use. AND - it is the Long Username that I was talking about. Sorry for the misinformation! I am not real proficient with the vi editor - so I am still trying to work out how I can edit it from a shell script. I am just not sure how to hit "a" to insert ans ZZ to close and save. I am going to do some more googling and I'll let you know.

Code:
# Changing user information for darenhunter.
# Use "passwd" to change the password.
##
# Open Directory: /Local/Default
##
Shell: /bin/bash
Full Name: daren
Office Location:
Office Phone:
Home Phone:
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~                                                                               
"/etc/chfn.aPWgeJ" 10L, 203C


Top
 Profile  
 PostPosted: Tue Apr 13, 2010 9:55 am   

Joined: Mon Apr 12, 2010 9:07 am
Posts: 5
Code:
finger shortname | awk '/Name:/ {print $4}'
This will print the User Name field I was talking about. Still trying to figure out how I can use the chfn to change the name in a script. I'll post back if I figure it out. Probably no one cares in the least. :D


Top
 Profile  
 PostPosted: Tue Apr 13, 2010 11:10 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Code:
login=your_login_name
full_name=$(finger -s $login | awk -v loginName=$login '$1 ~ loginName {print $2}')
echo "$full_name"
but it doesn't work if fullname is two or more words :(
plus, if user is connected more than once there are as many lines as there are connections.

If mac has /etc/passwd, then parsing it would be more easy.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP