LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2008, 11:25 AM   #1
unihiekka
Member
 
Registered: Aug 2005
Distribution: SuSE Linux / Scientific Linux / [K|X]ubuntu
Posts: 273

Rep: Reputation: 32
Expect script, scp and find command


I have a script that requires a password as entry (yes, I know it is not safe to do so...), which is then entered automatically with the expect command:

Code:
#!/usr/bin/expect -f
set pass [lindex $argv 0]
spawn -noecho scp file username@server:/folder/
...
which works fine. However, I have no idea how to recursively copy directories, because

Code:
spawn -noecho scp -r username@server:/folder/
does not work. It gives the the options of scp. Somehow I am not allowed to pass arguments of scp to spawn, I guess.

Another thing is that I would like to copy certain files of a certain types to the server and not whole directories. Without the expect interpreter (but with bash, so the first line would read #!/bin/bash) I would do something like:

Code:
find ./ -name "*.filetype" -exec spawn scp "{}" username@server:/folder \; -print
but then I get >>invalid command name "find<<. Probably because "find" is a part of the bash interpreter and not expect. Does anyone have an easy solution to this? Or a not so easy one, but a solution that I can understand (me = advanced n00b)?
 
Old 10-17-2008, 03:11 PM   #2
mallux
Member
 
Registered: Jun 2007
Location: London, UK
Distribution: Ubuntu, RHEL, Fedora
Posts: 46
Blog Entries: 1

Rep: Reputation: 16
Quote:
Originally Posted by unihiekka View Post

Code:
spawn -noecho scp -r username@server:/folder/
does not work. It gives the the options of scp. Somehow I am not allowed to pass arguments of scp to spawn, I guess.
You haven't specified where you want to copy from (like "file" in your first example) - if you want to copy everything starting in the current directory you would need to do:

Code:
spawn -noecho scp -r . username@server:/folder/
But you should really investigate rsync which is ideal for the type of copying that you want to do, particularly if you want to include/exclude certain filenames. Using find to fork a separate scp process for every file would not be terribly efficient.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unexpected curly braces in expect script spawn command & bash suid problem slinx Programming 1 05-02-2008 01:47 PM
How to use EXPECT command to scp or ssh? thefountainhead100 Linux - Software 6 03-28-2008 06:41 PM
exec the expect command in a shell script wanghao Linux - Networking 6 11-23-2007 11:06 PM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 04:38 PM
problem with find command in script cojo Linux - Software 3 05-26-2004 10:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration