At 08:22 PM 9/10/2001 +0000, you wrote:
Why not try;
xterm -fg black -bg white -e /bin/bash -c ` /usr/bin/sudo /sbin/ifconfig |grep "inet addr" &
Well I have discovered that the way to keep the window open is to give xterm the -hold switch, unfortunately the script isn't working correctly, because I"m getting the whole output of ifconfig, not just the grep. I have found that the bash -c doesn't seem to make any difference, BTY. xterm -fg black -bg white -hold -e /usr/bin/sudo /sbin/ifconfig |grep "inet addr" Is the current incarnation. Those who cannot remember the past
are condemned to repeat it. ---- George Santayana ------------ ========================================
---------------------------------------------------- Jonathan Wilson System Administrator Cedar Creek Software http://www.cedarcreeksoftware.com Central Texas IT http://www.centraltexasit.com
Hi Almost there, try quoting the command to sudo: xterm -fg black -bg white -hold -e /usr/bin/sudo \ ' /sbin/ifconfig | grep "inet addr" ' It works with su. By the way, if you only want the IP addresses shown, you could try replacing the grep by sed: '/sbin/ifconfig | sed -n "s/\(inet\ addr:\)\([0-9.]*\).*/\2/p"' Looks awful, but it works. Bye, Tim On Mon, Sep 10, 2001 at 02:43:59PM -0500, JW wrote:
xterm -fg black -bg white -hold -e /usr/bin/sudo /sbin/ifconfig |grep "inet addr"
Is the current incarnation.
At 01:12 AM 9/11/2001 +0200, you wrote:
Hi
Almost there, try quoting the command to sudo:
xterm -fg black -bg white -hold -e /usr/bin/sudo \ ' /sbin/ifconfig | grep "inet addr" '
Nope, both of these cause sudo to get unhappy: /usr/bin/sudo: /sbin/ifconfig |grep "inet addr": command not found /usr/bin/sudo: /sbin/ifconfig | sed -n "s/\(inet\ addr:\)\([0-9.]*\).*/\2/p": command not found I also tried: xterm -fg black -bg white -hold -e /usr/bin/sudo /bin/bash -c /sbin/ifconfig |grep "inet addr" With quotes, single quotes, parenthesis and back ticks in various arrangements, with varying results, including printing the whole contents of ifconfig again. The back ticks came the closest to working: addr:192.168.0.110: inet: command not found I discovered that bash seems to be attempting to run the output of the grep as commands, because when I switch to just grepping for addr, I get the following Link: eth0: command not found Please try my full script yourself, if you have a mind to, in order to see first hand how it's acting: #!/bin/bash xterm -fg black -bg white -hold -e /usr/bin/sudo \ `/sbin/ifconfig | sed -n "s/\(inet\ addr:\)\([0-9.]*\).*/\2/p"` I think I could but all the bash stuff in a secondary script and have sudo run that script, but I'm picky and don't want to do it that way, unless someone can convince me that doing it my preferred way is impossible :-) P.S. what's the final p on your sed script do? I've never seen that before.
It works with su. By the way, if you only want the IP addresses shown, you could try replacing the grep by sed:
'/sbin/ifconfig | sed -n "s/\(inet\ addr:\)\([0-9.]*\).*/\2/p"'
Looks awful, but it works. Bye, Tim
---------------------------------------------------- Jonathan Wilson System Administrator Cedar Creek Software http://www.cedarcreeksoftware.com Central Texas IT http://www.centraltexasit.com
Hi again, I think I can help you out this time: #!/bin/bash IF_ADDR=$(/usr/bin/sudo /sbin/ifconfig | \ sed -n 's/\(\ *inet\ addr:\)\([0-9.]*\).*/\2/p') xterm -fg black -bg white -hold -e echo "$IF_ADDR" So, what happens is like this: 1) ifconfig is run via sudo. 2) the ifconfig output is being run through sed, which is told not to produce any output (-n) but the result of the substitution (p), which is the second (2) matching regular expression ([0-9.]*) (my apologies) 3) the result of all this is stored as a string in variable IF_ADDR 4) the content of IF_ADDR is echoed in an xterm Apparently, you're not very familiar with bash shell quoting. Let me explain: Double quotes (" "): allow shell expansion or substitution. Straight ticks (' '): literal, no shell expansion or substitution. Back ticks (` `) or $( ): replace with the output of the enclosed command. As it happens, this has become an illustrative example of all three kinds. P.S. the script should be run in the foreground, i.e. without a trailing &. Good luck, Tim
participants (2)
-
JW
-
Tim van Venrooij