How to get expect -c to work in single line rather than script How to get expect -c to work in single line rather than script shell shell

How to get expect -c to work in single line rather than script


Got it:The following code scps a file called Sean_Lilly.zip from my box to another box without entering a password:

expect -c "spawn /usr/bin/scp Sean_Lilly.zip adaptive@10.10.12.17:/opt/ams/epf_3_4/Sean_Lilly.zip; sleep 5; expect -re \"password\"; send \"ad\r\n\"; set timeout -1; expect -re \"100%\";"

I know this can be done by setting passwordless ssh access between the two boxes but I wanted to do it in one command line using expect. Thanks fuzzy lollipop for the inspiration. Note if you run expect -d -c "spawn ... you get excellent debug on what is happening including whether your regex is good enough


You are missing a ; on the first one line example at the end of the last command. And there is a better way to pattern match the password.

try the following:

expect -c "spawn /usr/bin/scp xmlEventLog_2010-03-22T14-28-36_PFS_1_2.xml adaptive@10.10.12.17:/opt/ams/epf_3_4/xmlEventLog_2010-03-22T14-28-36_PFS_1277900174_2.xml; expect -re \".*password.*\"; send 'ad\r\n';"