This is part of code in an expect script, I have a problem with searching IP addresses from a file whose name is in the variable $filename
.
#!/usr/local/bin/expect --
###Made by Etihkru####
set env(TERM) vt100
set env(SHELL) /bin/sh
set env(HOME) /usr/local/bin
exp_internal 1
set PASSWORD eri
set SIU [lindex $argv 0]
match_max 1000
if {$SIU == ""} {
puts "Missing name of SIU. Run command as perl SIUADD FRTXXX"
exit
}
spawn ssh mashost
set USER admin
set PASS hidden
expect {
"assword" {send "$PASSWORD\r"}
}
expect "ranosusr@rn2osscs603"
send -- "cd /var/opt/ericsson/edd/ARNE_SIU \r"
expect "ranosusr@rn2osscs603"
send -- "grep -il $SIU *\r"
set prompt {ranosusr@rn2osscs603> }
expect -re "(FXL\\S+\\.xml).*$prompt$"
set filename $expect_out(1,string)
send -- "cat $filename | grep 'url=' \r"
expect -re "something.*$prompt$" //Expect this ip adreess ???
set IP $expect_out(1,string)//put it to variable IP ???
spawn ssh admin@$ip
expect {
-re "RSA key fingerprint" {send "yes\r"}
timeout {puts "Host is known"}
}
expect {
"assword" {send "$PASS\r"}
}
expect "Osmon>"
send -- "resumePMMeasurements STN=0,MeasurementDefinition=0 sftp://pmup-rn2sossv605:eric@10.211.149.60/GRAN/rn2sossv605/$SIU/NeTransientUp \r"
expect "Osmon>"
send -- "getalarmlist \r"
expect -re "(\Operation Succeed\)"
send -- "rev \r"
expect "Osmon>"
send -- "subscribe 10.211.149.40 1 \r"
expect "Osmon>"
send -- "getsubscriptionstatus 1 \r"
expect "Osmon>"
interact
This is the ouput:
expect: does "> cat FXL704_FRTAMX_SIU_ARNE.xml | grep 'url=' " (spawn_id exp4) match glob pattern "ranosusr@rn2osscs603"? no
expect: does "> cat FXL704_FRTAMX_SIU_ARNE.xml | grep 'url=' \r\r\n" (spawn_id exp4) match glob pattern "ranosusr@rn2osscs603"? no
<emUrl url="10.80.31.123"/>
expect: does "> cat FXL704_FRTAMX_SIU_ARNE.xml | grep 'url=' \r\r\n <emUrl url="10.80.31.123"/>\r\r\n" (spawn_id exp4) match glob pattern "ranosusr@rn2osscs603"? no
ranosusr@rn2osscs603>
expect: does "> cat FXL704_FRTAMX_SIU_ARNE.xml | grep 'url=' \r\r\n <emUrl url="10.80.31.123"/>\r\r\nranosusr@rn2osscs603> " (spawn_id exp4) match glob pattern "ranosusr@rn2osscs603"? yes
I need the pure IP address, cleared from other characters (e.g. 10.80.31.123
), because I need to use it in next SSH login, so I need to assign it to a variable $IP
.