Expect script to change password caused by ssh

I currently have a bash script that uses the wait in it, performing some actions on ssh. It looks like this:

#!/bin/bash #some bash stuff here ... /usr/bin/expect -c ' spawn somescript.sh expect "password:" send "$PASSWD" ' ... 

somescript.sh executes commands to the remote server on top of ssh, but now my login requires changing the password. I tried

 /usr/bin/expect -c ' spawn somescript.sh expect "password:" send "$PASSWD" expect "current password" send "$PASSWD" expect "new password" send "$NEWPASSWD" ' 

but I get an error:

 WARNING: Your password has expired.\n Password change required but no TTY available. 
+4
source share
3 answers

So, somescript.sh creates an ssh connection, and then you get a TTY missing message.

Try the -t option!

From ssh man page :

 -t Force pseudo-tty allocation. This can be used to execute arbi- trary screen-based programs on a remote machine, which can be very useful, eg, when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty. 
+2
source

This can be solved by directly contacting the field using ssh (i.e. not in the script).

Do this and he will prompt you to change your password. Do this and the error will disappear.

0
source

It looks like you are trying to run ssh user@server passwd , but since your password has expired, you must change it first. Probably, when you run the expected spawn user@server , it will ask you to change the password, and it will work.

0
source

Source: https://habr.com/ru/post/1498499/


All Articles