General
cancel
Showing results for 
Search instead for 
Did you mean: 

How to run multiple commands using expect?

hpmuru
Established Member

How to run multiple commands using expect?

Hi Gurus,

 

I am in process of creating a script to get multiple commands o/p from some set of servers and collecting its output in a single file.

 

My below commands works fine..

/usr/bin/expect -c "spawn ssh uname@hostname "'head /etc/hosts'" ; expect "'password:'" ; send "usr-passwd" ; interact "

 

but not this one..

/usr/bin/expect -c "spawn ssh uname@hostname "'head /etc/hosts; uname -a'" ; expect "'password:'" ; send "usr-passwd" ; interact "

 

this is because expect splits commands due to semicolon added between them. Is there any escape character which can be used here to fix this??

 

Regards,

Murugan

2 REPLIES
Dennis Handly
Acclaimed Contributor

Re: How to run multiple commands using expect?

>a script to get multiple commands output

 

Any reason you don't create a script that does the multiple commands and then run expect on that script?

hpmuru
Established Member

Re: How to run multiple commands using expect?

Hello ,

 

Thank you, for your response.

 

My goal is to get multiple commands output using a single/simple script from different servers. Also, I would like to give the username and password in the same script itself. Password less login using ssh-key or other solutuions doesn't satisfy my requirement.