scp not working in expect script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scp not working in expect script
# 1  
Old 11-06-2013
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:
Code:
#!/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 tar file never transfer from local machine to remote machine.
Anyone have any idea?

Last edited by Franklin52; 11-06-2013 at 10:24 AM.. Reason: Please use code tags
# 2  
Old 11-06-2013
Add the full path of the scp in the script.
Code:
[root@client ~] which scp
/usr/bin/scp

Print the error you have got to investigate more on it.

Last edited by Franklin52; 11-06-2013 at 10:24 AM.. Reason: Please use code tags
# 3  
Old 11-06-2013
Hi
When I run debug mode i get below error:

Code:
root@debian:~# expect -d copyfiles 
expect version 5.45
argv[0] = expect  argv[1] = -d  argv[2] = copyfiles  
set argc 0
set argv0 "copyfiles"
set argv ""
executing commands from command file copyfiles
spawn /usr/bin/scp /var/spool/sms/failed.tar.gz abc@10.10.12.2:/home/abc
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {13593}

expect: does "" (spawn_id exp6) match glob pattern "elaine@10.10.12.2's password: "? no
elaine@10.10.12.2's password: 
expect: does "abc@10.10.12.2's password: " (spawn_id exp6) match glob pattern "abc@10.10.12.2's password: "? yes
expect: set expect_out(0,string) "abc@10.10.12.2's password: "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "abc@10.10.12.2's password: "
send: sending "pass.word\r" to { exp6 }

Any idea how to resolve it?
# 4  
Old 11-07-2013
Stupid question, but could you ditch expect and use scp in batch mode? It may require setting up an SSH key pair, but assuming you are allowed to do such a thing it would make your life an awful lot easier.

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiple expect/send statements not working in shell script

Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect. The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits #!/bin/bash expect -c ' spawn... (2 Replies)
Discussion started by: skorada
2 Replies

2. Shell Programming and Scripting

SFTP or scp with password in a batch script without using SSH keys and expect script

Dear All, I have a requirement where I have to SFTP or SCP a file in a batch script. Unfortunately, the destination server setup is such that it doesn't allow for shell command line login. So, I am not able to set up SSH keys. My source server is having issues with Expect. So, unable to use... (5 Replies)
Discussion started by: ss112233
5 Replies

3. Shell Programming and Scripting

Using Expect and scp. Not moving directories

An Expect script using scp to copy directories is not moving the subdirectories as wanted. The directory structure is: computerA (user 'test') /home/test/parentDir/subdir1 /home/test/parentDir/subdir2 and I want them copied to computerB (user 'archive') /home/archive/subdir1... (1 Reply)
Discussion started by: nohj ordpl
1 Replies

4. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

5. 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

6. Shell Programming and Scripting

Expect script not working in crontab with minicom

Hi All, I am testing expect script in command prompt without issue, but in crontab it is not working, i check the output error as below: #cat /var/log/testexp.log spawn minicom -C /var/log/minicom1.log No cursor motion capability (cm) AT+COPS=? I am new in scripting, together... (1 Reply)
Discussion started by: elingtey
1 Replies

7. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

8. Shell Programming and Scripting

Expect Script Not working with Crontab

I have the following expect script sitting on a Linux box. === #!/usr/bin/expect -f # # backup.expect # # Expect script to backup a firewall via a SSH session # # set firewall set username set password set prompt set filename match_max 50000 spawn ssh -l... (2 Replies)
Discussion started by: alagondar
2 Replies

9. Shell Programming and Scripting

ssh is not working while calling through expect shell script

Hi, Please share you experience and way out on below error:--> #!/bin/bash -xv FILE=login.txt + FILE=login.txt CONNECT=sshlogin.exp + CONNECT=sshlogin.exp SERVERNAME=$1 + SERVERNAME=192.168.12.1 MyServer="" + MyServer= MyUser="" + MyUser= MyPassword="" + MyPassword= exec 3<&0 +... (6 Replies)
Discussion started by: manish_1678
6 Replies

10. Shell Programming and Scripting

scp is not working through sh script

Hi All, I am generating a ~ delimited file from oracle table and then transfer it to another server through scp. if then scp $COM_DIR/ABC.txt unix.nam.nsroot.net:/home/magna/dum/ABC.txt else echo "File does not exist, please check" >>$LOG fi The script generates the file,... (8 Replies)
Discussion started by: Amit.Sagpariya
8 Replies
Login or Register to Ask a Question