Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

Get the output from expect script in a variable

$
0
0

I have an expect script which provides the IP address:

#!/bin/expect -f
set nodename [lindex $argv 0]
spawn virsh console $nodename
expect "Escape character is"
send "\n"
expect "localhost login: " {
    send "root\n"
    expect "Password: "
    send "cloud123\n"
}
expect "~]#" {
        send "\n"
        send "ifconfig | grep 192.168.1. | awk \'{print \$2}\'"
        send "\n"
        expect '(\d+\.\d+\.\d+\.\d+)'
        send "logout"
}

I want the script to return this IP address. I am calling this expect script from a shell script as below

#!/bin/bash
ip=$(expect GetIP.exp nodetwo)
echo $ip

How can I make my expect script return output to the shell script?


Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>