Hi All,
Hoping you can help as im in desperate need... I'm very new to unix scripting so apoligies,
I have setup an expect script in order to log into a node on our network, This will provide an output as per the below
*********** information:
*************: n/a
TEST IP : n/a
****************: n/a ***************: n/a
********* Information:
**********: 345:66:25434
**********: 345:66:8468
*********: n/a
*******************: n/a
*******************:
***** ***** **: 33:345:66
TEST IP : 123.45.67.89
What I need to be able to do is read the IP address next to where it says TEST IP and then use this in another command. Problem I have is the IP does not always display in the bottom TEST IP line sometimes it can be in the first TEST IP line and N/A will be next to the second.
Essentially I need to read the IP address next to TEST IP and then use in another command. Would anyone be kind enough to help me out please. Sorry for the stars but as its security info I cant show it.
Thanks for your response's guys, So this is a print output from within an expect script. I need the IP addresses to be read and then I want to execute another command using that ip as the variable.
if the next script is occuring almost simultaneously with the first script, you can just set a variable to the value of the ip address and then run the next command (see sample below) ...
If this condition is true for more than one IP MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2}' file)
you can use exit to get only the first. MYIP=$(awk '/TEST IP/ && !/n\/a/ {print $2;exit}' file)
This will make this work ping $MYIP
Hi Guys
Thanks for your responses See below which is what I put together based on the feedback.. However its not working please can you advise what im doing wrong
You need to do the parsing/extraction natively within the expect script. The solutions given so far require a spawning of 'awk' which I'm not sure if expect allows.
I'm no expect guru, but maybe other will help.
Study tk and tcl tutorials online, as expect is made from, and scripted with, these languages.
Alternatively, I have written expect-like scripts that mostly ran in the parentheses piped to stdin, examining the log file where stdout and stderr are being written. This rescues me from learning another script langage. It does have minor problems getting control of /dev/tty if that is where passwords and such are read from. For instance, a primitive remote smtp/esmtp email client from telnet:
$ (
>>my_mailer_log
<script that examines log file my_mailer_log for progress and generates input>
) | telnet mailhost 25 > my_mailer_log 2>&1
Hi Guys,
Just to follow up really, I managed to complete what i needed by using a perl script which then called an expect script in order to login to the relivant elements and run the commands required.