I have a expect script where I want to check uname -a.
if the remote server is Linux then I will run few more remote command using expect. If it is Aix then I will run few other set of commands. However I am not able to create the if condition. Can any one please help me?
expect <<'EOF'
spawn ssh user_name@server "uname -a"
set count 0
expect {
"password:" {
send password\r
exp_continue
}
"Permission denied" {
incr count
exp_continue
}
}
set strname LINUX
set results $expect_out(buffer)
if {$strname == $results}
{
puts $results
}
EOF
The
uname -a
command output will not just have the wordLinux
orAix
, but also the more info. So, it would be better to useregexp
to check whether if it contains the word.Else, you should have used
uname
command alone which will only produce what is indeed needed to us. In that case, your given code will work fine.