LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-27-2010, 03:57 PM   #1
s7upify
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Rep: Reputation: 0
SCP with wildcard in Expect


Hey there
I am attempting the copy all the files within a directory using SCP from within an expect routine. I do not want to use recursive directory transfer and am usually able to do this with a wildcard asterisk.

Here's what I am getting:
mach1:~/folder # vi exp7
mach1:~/folder # /root/folder/exp7 passw mach2 /root/folder
spawn scp /root/folder/* root@mach2 :/root/folder/
Password:
/root/folder/*: No such file or directory
Killed by signal 1.

You can see the spawn command I call there. Here it is from vi:
spawn scp $curr_dir/* root@$REMOTEHOST:$curr_dir/

The parameters are correct, so I can narrow the problem down to the wildcard. How do I implement it?

Thanks!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-27-2010, 04:52 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

To get shell glob'ing working, you'll have to run the command through a shell, rather than getting expect to run the command directly.

Try:
spawn bash -c "spawn scp $curr_dir/* root@$REMOTEHOST:$curr_dir/"
instead. I can't remember off-hand how tcl/expect handles $XXX variables inside quotes, so you might have to mess about with the quoting. Probably not, though.

Dave
 
2 members found this post helpful.
Old 09-28-2010, 08:32 AM   #3
s7upify
LQ Newbie
 
Registered: Aug 2010
Posts: 6

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by ilikejam View Post
spawn bash -c "spawn scp $curr_dir/* root@$REMOTEHOST:$curr_dir/"
Thanks Dave it worked like a charm! Just remove the spawn after the -c " (I assume you just copy and pasted :P).

This works:

spawn bash -c "scp $curr_dir/* root@$REMOTEHOST:$curr_dir/"

Last edited by s7upify; 09-28-2010 at 08:33 AM.
 
Old 07-18-2011, 11:11 AM   #4
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by s7upify View Post
Thanks Dave it worked like a charm! Just remove the spawn after the -c " (I assume you just copy and pasted :P).

This works:

spawn bash -c "scp $curr_dir/* root@$REMOTEHOST:$curr_dir/"

Not, working for me. I am also stucked in the same issue.

I want to scp these files.

Code:
[root@box1 ~]# ls -lrth /root/*.up
-rw-r--r-- 1 root root  0 Jul 18 21:19 /root/1.up
-rw-r--r-- 1 root root  0 Jul 18 21:19 /root/2.up
-rw-r--r-- 1 root root 29 Jul 18 21:37 /root/last.up

This is how I am using it.
Code:
[root@box1 ~]# cat dev.sh
#!/usr/bin/expect -f
set timeout 20
set files [lindex $argv 0]
set rdir  [lindex $argv 1]
spawn bash -c "scp $files vikas@192.168.1.100:$rdir"
expect "*?assword:*"
send -- "vikas\r"
send -- "\r"
expect eof
[root@box1 ~]#
[root@box1 ~]# ./dev.sh /root/*.up /home/vikas/
spawn bash -c scp /root/1.up vikas@192.168.1.100:/root/2.up
vikas@192.168.1.100's password:
scp: /root/2.up: Permission denied
Killed by signal 1.
However, without a wildcard it works fine.
Code:
[root@box1 ~]# ./dev.sh /root/1.up /home/vikas/
spawn bash -c scp /root/1.up vikas@192.168.1.100:/home/vikas/
vikas@192.168.1.100's password:
1.up                                                                                                                                  100%    0     0.0KB/s   00:00
[root@box1 ~]#

Any ideas people.
 
Old 07-18-2011, 11:43 AM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Your "/root/*.up" is getting expanded by the shell before it gets into the expect script.

Try:
Code:
./dev.sh '/root/*.up' /home/vikas/
 
Old 07-18-2011, 12:12 PM   #6
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Thanks ilikejam.

This worked for me.

Code:
./dev.sh /root/\*.up /home/vikas/
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
expect: line seems to match exactly, however expect thinks not deadeyes Linux - General 5 06-16-2010 06:05 PM
Expect script, scp and find command unihiekka Programming 1 10-17-2008 03:11 PM
scp does not work and gives the following error message: scp: FATAL: Executing ssh1 i akay Linux - Networking 16 09-28-2008 11:41 PM
How to use EXPECT command to scp or ssh? thefountainhead100 Linux - Software 6 03-28-2008 06:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:37 PM.

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
Open Source Consulting | Domain Registration