I use expect tu verify a password against ssh. I have tried to output via puts but I just get the end of the server response in the string.
How do I only get the puts values?
okk=$(expect -c "
set timeout 15
spawn ssh -p 22 [email protected]
expect {
\"(yes/no)\" {
sleep 1
send \"yes\n\"
exp_continue
}
\"(y/n)\" {
sleep 1
send \"y\n\"
exp_continue
}
password {
sleep 1
send \"$sshpw\r\"
exp_continue
}
Password {
sleep 1
send \"$sshpw\r\"
exp_continue
}
\"Last login\" {
puts \"yes\"
exit 1
}
\"Permission denied\" {
return \"no\"
exit 1
}
timeout {
puts \"timeout\"
exit 1
}
eof {
puts \"error\"
}
}
sleep 1
expect eof
")
echo $okk
onsectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nis
Two changes are needed to filter out everything except the output of
puts
:Use
spawn -noecho ssh -p 22 [email protected]
Add
log_user 0
afterset timeout 15
WARNING: if you hit a case that does not print anything in the EXPECT world, you will get an empty string in the BASH world. So, take care of this!