The following bash script does not work, because the wait command always returns 0, regardless of which remote script / tmp / my.sh exit code is returned.
any idea to make it work? thanks.
#!/usr/bash
user=root
passwd=123456abcd
host=10.58.33.21
expect -c "
spawn ssh -o StrictHostKeyChecking=no -l $user $host bash -x /tmp/my.sh
expect {
\"assword:\" {send \"$passwd\r\"}
eof {exit $?}
}
"
case "$?" in
0) echo "Password successfully changed on $host by $user" ;;
1) echo "Failure, password unchanged" ;;
2) echo "Failure, new and old passwords are too similar" ;;
3) echo "Failure, password must be longer" ;;
*) echo "Password failed to change on $host" ;;
esac
Edited 10:23 AM 11/27/2013
Thanks for the comments. Let me reiterate the problem,
The main script should run on Linux A silently , during which it calls another script my.sh on server B without supervision . Question: how to get my.sh exit code ?
This is why I cannot use the ssl_key approach in my case, which requires at least one temporary configuration.