Expect inside while loop
Hi Guys,
Its been long time since i've posted on this forum. But here it is , trying my hands on shell script once again to automate a task which has been done manually for many weeks now. The task is to scp files from server A to B , However please note that password-less scp cannot be used. So i am trying to script expect inside a shell script. I am trying to put all things inside only one script rather than calling expect script from shell script. Please find below code, Code:
And the above code is not working as desired , Either it terminates when i use " or it just loops for all the files and exits. Kindly help or point me in right direction. Regards, Nitin |
http://stackoverflow.com/questions/7...multiple-files
here you can find a nice function to send password. also you can try to scp all the files in one: Code:
filelist=$(cat filelist2.txt) |
Hi Pan64,
Thanks for your reply , According to your link and code i've changed the code as below. Code:
> filelist1.txt Code:
Regards, Nitin |
in your find command you can try to use -print instead of -exec ls -lrt {} that would make it simpler I think.
instead of: cat filelist1.txt | awk '{print$9}' > filelist2.txt use: awk '{print$9} filelist1.txt > filelist2.txt but will not need any more (if you use -print) instead of while read inputline .... done < filelist2.txt use awk 'script' filelist2.txt > filelist3.txt in this script you need to remove newline chars too, you need to have only one single line in filelist3.txt actually I do not know what is that cut good for.... |
Hi Pan64,
The output of -print is as below Code:
./1_1765_842824583.dbf I have also changed the newline characters to space using tr as below , Code:
tr '\n' ' ' < filelist2.txt Code:
Code:
bash-3.2$ ./mov3.sh Nitin |
yes, you mixed " and ':
expect_password 'scp '$filelist' oracle@10.10.10.10:/oarch/adb/' |
Hi Pan64,
I have changed " to ' as below , Code:
expect_password 'scp '$filelist' oracle@10.10.10.10:/oarch/adb/' Code:
1_1765_842824583.dbf 1_1766_842824583.dbf 1_1767_842824583.dbf 1_1768_842824583.dbf can't read "filelist": no such variable One more important thing which i forgot to mention while creating thread is the server is AIX 6.1 Regards, Nitin |
Hi Pan64,
After making some more changes now the code looks like Code:
Code:
expect_password 'scp $filelist2 oracle@10.10.10.10:/oarch/adb/' Code:
Code:
Nitin |
whould be nice to see the whole script...
expect_password 'scp '$filelist' oracle@10.10.10.10:/oarch/adb/' should work if the variable $filelist contains the list of the files. Something has been mixed.... |
Hi Pan64,
Thanks for your prompt replies. Below is the code now. Code:
> filelist1.txt to avoid the error which i got in previous comment , i have now given whole path. Code:
bash-3.2$ ./mov3.sh Nitin |
Quote:
I got below code working , Looks like scp is not accepting multiple files Code:
> filelist1.txt Nitin Chauhan |
No, I'm really sorry, but I think scp supports copying several files "in one".
http://expert-mode.blogspot.hu/2011/...ple-files.html You need to insert set -xv at the beginning of your script and see the result. (this will not influence the script just will print a lot of information about execution). The problem I saw is: /arch/ADB/$filelist2 is not an acceptable syntax. (this can work only if filelist2 contains one file) |
Quote:
Thanks for your help. Working code is as below. I have put the whole expect function inside a while loop. Code:
Nitin |
All times are GMT -5. The time now is 07:31 PM. |