Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expect script change password prompted over ssh

Tags:

bash

ssh

expect

Currently I have a bash script that uses expect in it while doing some things over ssh. It looks like:

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

somescript.sh does commands to a remote server over ssh, but now my login requires a change of password. I've 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 saying:

WARNING: Your password has expired.\n Password change required but 
no TTY available.
like image 839
dwu Avatar asked Aug 22 '13 22:08

dwu


1 Answers

So, somescript.sh makes an ssh connection and then you get an error about TTY not being available.

Try -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, e.g., when implementing menu services.  Multiple -t
     options force tty allocation, even if ssh has no local tty.
like image 86
Aleks-Daniel Jakimenko-A. Avatar answered Oct 05 '22 07:10

Aleks-Daniel Jakimenko-A.