Hide the output of spawn ssh user@server

Hi All,

I have written one script, which is connecting 3 diffrent servers and executing script placed on those.
It is smthing like:

spawn ssh user@server1
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename1 \r"
expect "$"
expect eof
spawn ssh user@server2
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename2 \r"
expect "$"
expect eof
spawn ssh user@server3
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename3 \r"
expect "$"
expect eof

But problem I am facing here is that:

On console I am getting lots of unwanted outputs of spawn ssh user@server1 and spawn ssh user@server2 and spawn ssh user@server3 along with those scripts (file1, file2, file3) responses.

where as i need just outputs of :

send " sh ./filename1 \r"
send " sh ./filename1 \r"
send " sh ./filename3 \r"

So could you please suggest any solution for this?

Thanks in advance!

Regards,
KD

Have you tried using /dev/null to silence the output?

Maybe something like this for what you need removed from the output:

send "pw \r" > /dev/null

You should try this:

(
spawn ssh user@server1
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename1 \r"
expect "$"
expect eof
) > /dev/null
(
spawn ssh user@server2
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename2 \r"
expect "$"
expect eof
) > /dev/null
(
spawn ssh user@server3
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename3 \r"
expect "$"
expect eof
) > /dev/null

Hi,

First of all thanks for suggesting the solution.

But these solutions are not able to resove the problem.

both the suggestions are giving some errors.

Could any one suggest the appropriate solution?

Regards,
KT

I tried following options, but dint find solution:

send "pw \r" > /dev/null
 

and

 
(
spawn ssh user@server1
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename1 \r"
expect "$"
expect eof
) > /dev/null

Thanks in advance!

Regards,
KD

By default, spawn echoes the command name and arguments. The
-noecho flag stops spawn from doing this.

Man Page for expect (all Section 1) - The UNIX and Linux Forums

It is better security and simpler scripting to set up key files for PPKey and just shell script the ssh.

Try this:,
However note that all output will be hidden.

(
/usr/bin/expect <<EOD
spawn ssh user@server1
expect "*? assword:"
send "pw \r"
expect "$"
send " sh ./filename1 \r"
expect "$"
expect eof
EOD
) > /dev/null 2>&1

Three threads were merged into one.