Sample Header Ad - 728x90

Get the output from expect script in a variable

6 votes
3 answers
24280 views
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?
Asked by karan ratnaparkhi (111 rep)
Oct 28, 2015, 08:47 AM
Last activity: Mar 18, 2025, 03:22 PM