Hide the output of spawn ssh user@server | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Hide the output of spawn ssh user@server

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2013
KDMishra KDMishra is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 11 February 2013, 11:29 AM EST
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
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:


Code:
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

Last edited by Scrutinizer; 02-11-2013 at 06:51 PM.. Reason: code tags
Sponsored Links
    #2  
Old 02-09-2013
Azrael's Avatar
Azrael Azrael is offline
Registered User
 
Join Date: Sep 2011
Last Activity: 26 April 2014, 9:30 PM EDT
Posts: 91
Thanks: 30
Thanked 3 Times in 3 Posts
Have you tried using /dev/null to silence the output?

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

Code:
send "pw \r" > /dev/null

Sponsored Links
    #3  
Old 02-09-2013
dexdex200 dexdex200 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 25 February 2014, 7:57 AM EST
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
You should try this:


Code:
(
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

    #4  
Old 02-11-2013
KDMishra KDMishra is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 11 February 2013, 11:29 AM EST
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #5  
Old 02-11-2013
KDMishra KDMishra is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 11 February 2013, 11:29 AM EST
Posts: 16
Thanks: 2
Thanked 0 Times in 0 Posts
How to hide connection response during ssh user@server?

I tried following options, but dint find solution:

Code:
send "pw \r" > /dev/null

and

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

Thanks in advance!

Regards,
KD

Moderator's Comments:
Please use code tags next time for your code and data.

Last edited by Scrutinizer; 02-11-2013 at 06:52 PM.. Reason: Removed duplicate content
Sponsored Links
    #6  
Old 02-11-2013
DGPickett DGPickett is online now Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 16 September 2014, 1:22 PM EDT
Location: Southern NJ, USA (Nord)
Posts: 4,411
Thanks: 8
Thanked 539 Times in 517 Posts
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.
Sponsored Links
    #7  
Old 02-11-2013
dexdex200 dexdex200 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 25 February 2014, 7:57 AM EST
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
Try this:,
However note that all output will be hidden.

Code:
(
/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

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
User Input Automation without Spawn foghsho Shell Programming and Scripting 8 05-16-2012 02:26 AM
Help to hide shell terminal and run prompt program after ssh login for specified user franzramadhan Shell Programming and Scripting 1 09-29-2011 05:30 AM
passwordless entry using ssh from one user to a different user on the same server deshaipet AIX 3 08-20-2011 09:04 AM
ssh for different user account in a server configuration posix UNIX for Dummies Questions & Answers 1 04-09-2011 07:19 PM
spawn a process with a different user edgarvm Programming 8 11-09-2010 02:43 PM



All times are GMT -4. The time now is 01:28 PM.