Using Expect scripts to port files to different unix box


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using Expect scripts to port files to different unix box
# 1  
Old 10-05-2012
Using Expect scripts to port files to different unix box

Hello all,

I've been trying to design a script which will help me transfer files from one unix box to another. Following is the code:

Code:
 
#!/usr/local/bin/expect
spawn /usr/bin/scp ms_cp5_daily.ksh userid@cat:/prod/env/ms.txt
set pass xxxxxx
expect {
password: {send "$pass\r"; exp_continue}
       }

When I run the code I am getting following Error Messages

Quote:

spawn /usr/bin/scp ms_daily.ksh userid@cat:/prod/env/ms.txt
Host key for the host "cat" not found from database.
The fingerprint of the host public key is:
Babble: "xezes-helyt-mabuv-facod-pagid-fubim-kobyf-dazed-cecek-fecac-bexox"
RFC4716: "83:aa:33:5f:75:f3:c2:38:ef:94:ed:f4:f4:bc:ea:56"

You can get a public key's fingerprint by running
% ssh-keygen-g3 -F publickey.pub
on the key file.
Please select how you want to proceed.
cancel) Cancel the connection.
once) Proceed with the connection but do not save the key.
save) Proceed with the connection and save the key for future use.
Please select one (cancel, once, save):
And the file never gets transfered.

Can anyone shed some light on what is going on.. or if I've written something wrong in my code!?
# 2  
Old 10-05-2012
The first time you ssh connect it asks if you want to trust and save the remote host key. Later it is silent. Seems like a new host.
# 3  
Old 10-05-2012
If you are sure you trust the site you can respond to the prompt with something like the below:
Code:
expect -re "Please select one (cancel, once, save):" { exp_send "once\r"; exp_continue } \
       -re "Are you sure you want to continue.*"     { exp_send "YES\r"; exp_continue } \
       -re "(Password|password).*:.*"                { exp_send "$pass\r"; exp_continue } \
       eof                                           { puts "***Error connecting to........."; exit 1 }
       timeout                                       { puts "***Error connecting to(........"; exit 1 }

Or you can manually run the scp command one time and when asked(Please select one (cancel, once, save):) select 'save' if you trust the site.
# 4  
Old 10-08-2012
Quote:
Originally Posted by spacebar
If you are sure you trust the site you can respond to the prompt with something like the below:
Code:
expect -re "Please select one (cancel, once, save):" { exp_send "once\r"; exp_continue } \

Code:
      -re "Are you sure you want to continue.*"     { exp_send "YES\r"; exp_continue } \
      -re "(Password|password).*:.*"                { exp_send "$pass\r"; exp_continue } \
      eof                                           { puts "***Error connecting to........."; exit 1 }
      timeout                                       { puts "***Error connecting to(........"; exit 1 }

Or you can manually run the scp command one time and when asked(Please select one (cancel, once, save):) select 'save' if you trust the site.


Thanks for the code. I've tried every option, i.e. cancel, once, save. It still errored out.

Tried the code above....This is the error I got:

Code:
 
Babble: "xezes-helyt-mabuv-facod-pagid-fubim-kobyf-dazed-cecek-fecac-bexox"
RFC4716: "83:aa:33:5f:75:f3:c2:38:ef:94:ed:f4:f4:bc:ea:56"

You can get a public key's fingerprint by running
% ssh-keygen-g3 -F publickey.pub
on the key file.
Please select how you want to proceed.
    cancel) Cancel the connection.
      once) Proceed with the connection but do not save the key.
      save) Proceed with the connection and save the key for future use.
Please select one (cancel, once, save): once
invalid command name "timeout"
    while executing
"timeout                                       { puts "***Error connecting to(........"; exit 1 }"
    (file "./scp_test2.exp" line 8)
An error occurred. The return code was 1

>ksh: once:  not found
An error occurred. The return code was 1

Tried the code without timeout.... still am getting an error.


Again, thanks for your help here...
# 5  
Old 10-08-2012
Manually do the 'scp' command for one file adding the "-v" switch so more information is logged to your screen and then post all the output logged to your screen.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX command to copy files from Windows to UNIX box

Hi Folks, I have a file name abc.xml in my windows machine at the location c:\ytr\abc.xml which I want to place at the unix box machine inside cde directory.. at the following location that is /opt/app/cde/ now the credentials of unix box are abc345 -->(dummyid) ftyiu88--->(dummy passwd) ... (4 Replies)
Discussion started by: punpun66
4 Replies

2. UNIX for Dummies Questions & Answers

Copy files from windows outlook in to UNIX box.

HI All, I am using a windows RDP machine . from the RDP i am opening a putty session of a unix server.i have outlook installed in the windows RDP machine, and if i get a file inthe outlook mail how can i copy it to a location in the putty unix machine. Please help me!!!! (3 Replies)
Discussion started by: mahesh300182
3 Replies

3. UNIX for Dummies Questions & Answers

Get files from Windows to Unix Box

Hi All, I am a new to unix scripting ...looking for directions from the Gurus. I want to create a FTP script to get Files from windows box to unix box. Thank you for your replies. (1 Reply)
Discussion started by: pbhk
1 Replies

4. HP-UX

Copying files from one unix to another unix box

Need a clarification .... While copying files from one unix to another unix box . I am working on two / three unix boxes which are all in a network.. in which home directory are mounted ..(I didn't understand what is the exact meaniing of that) So can i copy the files from one box to another... (2 Replies)
Discussion started by: girija
2 Replies

5. UNIX for Advanced & Expert Users

how to symbolic link to files on another unix box?

Hi there, Our vendor needs to have access to some files on our AIX box1, but we don't want them to have access to this box at all. We allow them to have access/logon to another AIX box2, is that possible that I create a symbolic link in box2 to point to those box1 log/config files ? How?... (1 Reply)
Discussion started by: TheGunMan
1 Replies

6. Shell Programming and Scripting

FTP some text files from Windows box to unix

hi all, can anybody help me with script or command to ftp some text file from windows machine to AIX machine. this is shud be done by executing a shell script. (1 Reply)
Discussion started by: suprithhr
1 Replies

7. Shell Programming and Scripting

how to compare all files in one unix box has been to copied to another unix box

Hi our unix admin has copied all files from one unix box to new unix box. We just need to confirm that all the file systems are copied properly. How to validate. (9 Replies)
Discussion started by: sravanreddym
9 Replies

8. Shell Programming and Scripting

Moving files from Unix box to a windows box

Hi All, I need a little help .I want to transfer a file from unix box to a windows box,but the problem i'm facing is that in windows box FTP is not enabled and currently it is nearly impssible to change setting on windows box,i can not use the ftp method ,in my shell script to transfer the file.... (2 Replies)
Discussion started by: Preet
2 Replies

9. Shell Programming and Scripting

Calling expect scripts from other expect scripts

Hi, First, let me explain the issue I am trying to solve. We have a lot of expect scripts with the duplicated send/expect commands. So, I'd like to be able to extract the duplicated code into the common scripts that can be used by other scripts. Below is my test where I am trying to call... (0 Replies)
Discussion started by: seva
0 Replies

10. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies
Login or Register to Ask a Question