How to put scp in background inside expect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to put scp in background inside expect
# 1  
Old 05-04-2010
How to put scp in background inside expect

Gents,

I have a wrapper script passing couple of information to an expect script mainly responsible for spawning scp and providing the password (which is transmitted down from the main script). the main script prepare the transfer to couple of servers, idea being to transfer the files in parallel to all servers.

Could not figure out how to put the scp in background in order to speed up the transfer and avoid waiting for them in sequence ?

Here is the expect script

Code:
#!/usr/bin/expect -f 
 
set user [lindex $argv 0] 
set host_name [lindex $argv 1] 
set password [lindex $argv 2] 
set remote_dir [lindex $argv 3] 
set work_dir [lindex $argv 4] 

log_user 0
#exp_internal 1 
spawn  scp -q ${work_dir} ${user}@${host_name}:${remote_dir}  

expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
#exp_send "script\r"
exp_send $password\r 
#exp_continue
}
}
interact  

#if {[fork] != 0} exit
#disconnect

#exit 1


Tahnks.

Last edited by Scott; 05-04-2010 at 12:11 PM.. Reason: Please use code tags
# 2  
Old 05-10-2010
You can use the & character:

Code:
exec/spawn scp ... &

# 3  
Old 05-10-2010
That you're having to shoehorn a stored plaintext password into scp's otherwise secure authentication system with expect is a subtle hint, writ in mile-high flashing neon letters: You're not supposed to do this. It's designed to stop you doing this for security reasons, use pre-shared keys instead -- it's what they're there for. There's instructions for it plastered all over the internet. They do exactly what you want except they don't have the security problems of storing a plaintext password, and don't have the poor reliability and extra wait and extra software requirements of an interactive input manually brute-forced with expect.
# 4  
Old 05-10-2010
Quote:
Originally Posted by Corona688
That you're having to shoehorn a stored plaintext password into scp's otherwise secure authentication system with expect is a subtle hint, writ in mile-high flashing neon letters: You're not supposed to do this. It's designed to stop you doing this for security reasons, use pre-shared keys instead -- it's what they're there for. There's instructions for it plastered all over the internet. They do exactly what you want except they don't have the security and reliability problems of your brute-forced plaintext password approach.
I fully agree.
Such an automatism should be implemented using PKI.

Last edited by radoulov; 05-10-2010 at 02:36 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Put currently running script into background

Hi All, Suppose I have a script and inside it I want/need to put it into background. I need the script to not react to SIGHUP signals. I tried: #!/bin/bash echo "" > test_disown mypid=$$ echo "PID=$mypid" ( kill -SIGSTOP $mypid jobs > myjobs #disown -h <job-spec> #kill -SIGCONT $mypid )... (6 Replies)
Discussion started by: JackK
6 Replies

2. Shell Programming and Scripting

scp script getting timed out with expect

Hi, I have an expect script where in i am trying to scp a folder but it is getting timed out. Any help will be appreciated. (I don't have the option for sharing keys) expect -c 2> /dev/null " spawn scp -r -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no root@10.10.10.10:test_dir... (2 Replies)
Discussion started by: temp_user
2 Replies

3. Linux

Not able to put ls -lR command in background

Hi All, i am trying to put ls -lRt command to run in the background but it fails. i continue to get output on screen and didnt get the command prompt right after i put the command in background. command i am using is ls -lRt & i am using bash. Can someone let me know how to... (6 Replies)
Discussion started by: omkar.jadhav
6 Replies

4. Shell Programming and Scripting

scp not working in expect script

Hi All, I run the scp command in shell prompt without issue, but when on expect script as below: #!/usr/bin/expect spawn scp /var/spool/sms/failed.tar.gz abc@10.10.12.2:/home/abc expect "abc@10.10.12.2's password: " send "abcfef\r" exit 0 It looks not working at all and the... (3 Replies)
Discussion started by: elingtey
3 Replies

5. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

6. Shell Programming and Scripting

How can put a background process to the foreground

Hi, guys: I am working on my own shell using c. When I put a process into the background, how can I put it back to the foreground using tcsetpgrp? Thanks (3 Replies)
Discussion started by: tomlee
3 Replies

7. UNIX for Dummies Questions & Answers

kill a command I am running / then put it to background

I have a command running in the foreground (and so my term window is locked up) and I want to kill it, then resume it in the background and go home. It is creating a zip file, and the file will be written to the current directory - no std in / std out issues. How do I do this? Kill it with a... (3 Replies)
Discussion started by: hindesite
3 Replies

8. Shell Programming and Scripting

put an interactive script in background after taking input

i am trying to find a way to put an interactive script in the background after taking input from the user a few test lines i was trying: date echo "Enter location" LOCATION= read LOCATION sleep 100 sleep 200 date for this small example i want the script to as the user for the... (7 Replies)
Discussion started by: epsilonaurigae
7 Replies

9. UNIX for Advanced & Expert Users

How to put vi file_names in background mode?

HI, When I used to work with Sun Solaris, I used to open multiple files and without closing it I will put them in background mode(using Ctrl-ZZ). In this way I will have 4-5 files open and using fg %2, I can vi the second file..while the rest of the files will be in background mode! I want to... (4 Replies)
Discussion started by: thiagoo
4 Replies

10. UNIX for Dummies Questions & Answers

How to store output in variable when put in background

Hi, How do I store following command output: export RESULT=`date` & It works when I do : export RESULT=`date` But what I need is when command put it background, I also need that output going to RESULT variable. Is there any way ? Thanks Sanjay (1 Reply)
Discussion started by: sanjay92
1 Replies
Login or Register to Ask a Question