The ssh from server0 to (server1,server2,server3) (no password need to SSH (trust exists between all servers and private key exists on all servers)) but a remote script on server (server1,server2 & server3 ) which starts a service/application needs a password for it to start. I want to be able to use ssh and run a command automatically on remote server. The remote script needs a password or expects a password answer with a password

ssh -n -o StrictHostKeyChecking=no  servername remotescrip

Enter application password to run the script:

1 Answer 1


Then use expect:

expect -c 'spawn ssh serversuser@server' \
-c 'expect "serverprompt" {send /path/to/your/script\n}' \
-c 'expect "Enter application password to run the script:" {send yourpassword\n}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .