lundi 10 décembre 2018

Getting an exit status stored to a variable inside an ssh command

I am trying to check that status of a prior command in list of commands sent to a server to change the password. When I just echo $? it works. when I store it to a variable like STATUS=$? and then echo $STATUS I get a blank line. And when I place the echo $? inside my if loop then returns something weird also. Below is the code of the ssh command for any advise on how to get this fixed.

ssh root@192.168.56.13 "printf '%s\n%s' "$PASSWORD" "$PASSCONFIRM" | passwd; STATUS=$?; echo $STATUS; if (( $STATUS == 0 )); then printf 'Password Changed Successfully\n'; else printf 'Password Change Unsuccessful\n'; fi; sleep 1;"
Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully

Password Change Unsuccessful
bash: ((: == 0 : syntax error: operand expected (error token is "== 0 ")

Aucun commentaire:

Enregistrer un commentaire