Register
It is currently Fri Nov 21, 2014 8:54 pm

Quick help with Script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Jun 28, 2011 2:25 pm   

Joined: Tue Jun 28, 2011 2:21 pm
Posts: 2
Trying to make a script to set a value in a .plist file which is based on the user's login name. basically trying to set a value to first.last@domain.com. So far I've got this:

#!/bin/bash
THEUSER=`osascript -e 'tell application "System Events" to get full name of (current user)'`
FIRST=`echo $THEUSER | awk '{ print $1; }'`
LAST=`echo $THEUSER | awk '{ print $2; }'`
defaults write com.microsoft.Communicator UserSIPID "$LAST.$FIRST@domain.net"

The script work fine and all however the problem is that our user account are "last, first" and the script reads the ',' attached to the last name so I end up with "first.last,@domain.com".

Is there a simply way to stop this comma from being read so that the out put to the .plist file is simply first.last@domain.com?

TIA.


Top
 Profile  
 PostPosted: Tue Jun 28, 2011 4:36 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Well, I didn't really understand what you were doing, but replacing:

Code:
LAST=`echo $THEUSER | awk '{ print $2; }'`


by:

Code:
LAST=`echo $THEUSER | awk '{ sub(/,$/, _, $2); print $2; }'`


should do what you want.

------

Some samples could help to make it bash(1) only.

------

EDIT :

Never mind, I think I got it.

Code:
#!/bin/bash

user=$(getent passwd "$USER")
IFS=': ' read -r _ _ _ _ first last _ <<< "$user"
echo "$first.${last%%,*}@domain.com"


If you want it all lowercase:

Code:
#!/bin/bash

user=$(getent passwd "$USER")
IFS=': ' read -r _ _ _ _ first last _ <<< "$user"
last=${last%%,*}
echo "${first,,}.${last,,}@domain.com"


Top
 Profile  
 PostPosted: Wed Jun 29, 2011 7:37 am   

Joined: Tue Jun 28, 2011 2:21 pm
Posts: 2
Thanks for the reply tried the script and they didn't work but I did some googling on the commands and realise that they are for linux it looks like. I neglected to mention in my original post that this is in OS X environment.


Top
 Profile  
 PostPosted: Wed Jun 29, 2011 10:52 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
I found an equivalent of getent(1) for OS X called dscl. You might be interested in it.

Also, since I don't have any Mac ( and I don't want one ;-) ), if you could give me a sample output of the command:

Code:
dscl . -read /Users/"$USER" RealName


I would consider rewriting the code with a proper parsing.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


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:  


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