help with a script

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 2
Reputation: bungley007 is an unknown quantity at this point 
Solved Threads: 0
bungley007 bungley007 is offline Offline
Newbie Poster

help with a script

 
0
  #1
Mar 13th, 2008
hey

I need a script to set a display to users ip's, I just need help putting it togther

the command i need to run is

setenv DISPLAY ipaddress:0.0

And i've got this to grab the ip and pop in the :0.0:

who|grep user | awk '{print $6}' |sed 's/(//g' | sed s/)/:0.0/g'

How do i now get the results of the above into one script that i can just run it will take ipaddress:0.0 and run the command ?

thx
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: help with a script

 
0
  #2
Mar 14th, 2008
Hey There,

This might help, in bash:

Shell Scripting Syntax (Toggle Plain Text)
  1. setenv DISPLAY $(who|grep $1 | awk '{print $6}' |sed 's/(//g' | sed 's/)/:0.0/g')

in sh or a shell that doesn't support the $() builtin, you could do:

Shell Scripting Syntax (Toggle Plain Text)
  1. setenv DISPLAY `who|grep $1 | awk '{print $6}' |sed 's/(//g' | sed 's/)/:0.0/g'`

Just add that line anywhere in your shell script. $1 would be the first arg passed to it, so you could call it like:

./yourscript username

Or whatever else you wanted to with it.

Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: bungley007 is an unknown quantity at this point 
Solved Threads: 0
bungley007 bungley007 is offline Offline
Newbie Poster

Re: help with a script

 
0
  #3
Mar 14th, 2008
Hi Mike

That's great I'll give it a try, I was originally doing this in ksh and couldn't understand why it wouldn't recodnise the setenv command but I realise now I need to do it in a c shell and that wouldn't reconise the $

Anyway, I'll give the latter a bash later, thanks a lot very helpful
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: help with a script

 
0
  #4
Mar 14th, 2008
That's right - also change "setenv" to "export" -- Man - I'm on a roll - time to slow down - I was concentrating on solving you're getting back the value I completely forgot that your csh "setenv" wouldn't work in bash and just pasted it between the extraction part. Good catch

Thanks

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
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