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

Recommended Answers

All 3 Replies

Hey There,

This might help, in bash:

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:

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.