I want to connect from ServerA to ServerB , and check Oracle Database Status and PendingLogs then record results, and use the result on ServerA ,and compare with the result on serverA and generate logs on serverA.

I used ssh -q [email protected] sh -s < /root/script.sh > /root/output.txt

but I still have to enter password manually.

  1. is there any way to turn off interactive login?

  2. how can I run script file via spawn ssh?

2 Answers 2


1- is there any way to turn off interactive login?

Yes, use public key authentication or sshpass to enter password.

2- how can I run script file via spawn ssh ?

Yes, use expect script. If you want to run some other script inside (awk), you need to escape the special characters (\$).

  • Then you have the other two options described in my answer.
    – Jakuje
    Nov 28, 2016 at 11:40
  • we are not authorize to use Public key Authentication , and sshpass -f /path/to/myfile ssh user@localhost is not working on CentOS. I used expect , but in my commands I have Awk and it doesn't support.
    – Reza
    Nov 28, 2016 at 12:15
  • you need to specify why it does not work. Probably you just need to install it? In the expect, it should not matter. You use it only to connect to the server, not to run any other tools (awk).
    – Jakuje
    Nov 28, 2016 at 12:17
  • 1
    you're right sshpass wasn't install. after installation sshpass problem solved. but we are not authorize to install and use this package. About AWK I found following format to use awk in expect. and it worked!! #set cmd "df -h | grep /dev/sda1 | exec awk '\{ print \$4\}'\r" send $cmd
    – Reza
    Nov 28, 2016 at 13:09

Actually, for the first question, you may not need to turn off the interactive login but as given by Jakuje, you can use sshpass or public key authentication as described in my blog . Another good reference for public key authentication is available here. The sshpass can be used with following format but initially sshpass needs to be installed to your system.

Command format:

sshpass -f password_file ssh user_login@ip_address_of_the_server

You must log in to answer this question.

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