Using expect command, spawn will not start sftp process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using expect command, spawn will not start sftp process
# 1  
Old 01-31-2013
Using expect command, spawn will not start sftp process

Hi all,

I have a script that runs sftp with expect so I can login and send a file in a cronjob. I've installed this on a couple other servers and it has been fine. However, this time on this machine, it seems to be giving me an issue. It won't move past the spawn sftp command and return a linux PID.

First the basics:

The server is running Red Hat Linux Release 7.3 (Valhalla)
uname -a shows Linux 2.4.20-28.7smp #1 SMP i686

I installed Expect-5.45 and Tcl-8.5.12

This is the script:
Code:
#!/usr/bin/expect -f
set location "."

spawn sftp username@secureftp.ftpserver.com
expect "password:"
send "userpw\r";
set timeout -1
send "put localfile.txt remotefile.txt\r";
send "quit\r"
expect eof

Pretty simple and straight forward, right?

When I run it with the -d flag to see what is happening, I get this output:
Code:
expect version 5.45
argv[0] = /usr/bin/expect  argv[1] = -d  argv[2] = ./scriptname.ftp
set argc 0
set argv0 "./scriptname.ftp"
set argv ""
executing commands from command file ./scriptname.ftp
spawn sftp username@secureftp.ftpserver.com
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child

And that is where it stops. It does not give me "spawn: returns [PID number]" and does not move on.

Any ideas? What am I missing here?

I appreciate any help you can give me, I've been searching and searching for an answer to no avail.

Thank you,

Laura

Last edited by Franklin52; 02-01-2013 at 04:51 AM.. Reason: Please use code tags
# 2  
Old 01-31-2013
Does it fail only under cron?
# 3  
Old 01-31-2013
I never even got as far as putting it on a cron job. This was running the script manually logged in as su (root).

if I run the "sftp username@secureftp.ftpserver.com" from the prompt I can connect with no issues, which is why I suspect the issue is with spawn.

Thanks,

Laura
# 4  
Old 01-31-2013
Sometimes an strace reveals what is going on, especially if you compare it to a good running host strace.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Expect: spawn id exp5 not open while executing "expect "$" { send "sudo su -\r" }"

Hi All, i am trying to ssh to a remote machine and execute certain command to remote machine through script. i am able to ssh but after its getting hung at the promt and after pressing ctrl +d i am gettin the out put as expect: spawn id exp5 not open while executing "expect "$" {... (3 Replies)
Discussion started by: Siddharth shivh
3 Replies

2. Shell Programming and Scripting

Sftp with spawn - can't execute

Hi All, I have below script which is just trying to sftp transfer a file to another server with 'expect' option. I have expect installed on the instance. Below is the script: #!/usr/bin/expect spawn sftp oracle@<HOST> expect "password:" send "<mypassword>\n" expect "sftp>"... (6 Replies)
Discussion started by: festerbg
6 Replies

3. Shell Programming and Scripting

Expect script error : send: spawn id exp4 not open

Hi, I am executing a expect script in while loop for doing telnet on list of servers stored in file as below : expect script : #!/usr/bin/expect -f set timeout 20 set ip set port if { == 0} { send_user "Usage: scriptname ip port\n" exit 1 } #exp_internal 1 log_user 0 spawn... (3 Replies)
Discussion started by: omkar.jadhav
3 Replies

4. Shell Programming and Scripting

Error in spawn and expect for password

Code Broken!! "cod generator ip=$loja" expect -c " # set timeout -1 set timeout 18 spawn scp -C /etc/samba/arkivo.sh root@$loja:/etc/samba/ expect { -re "*yes/no*"{ send "yes\r" exp_continue } -re "*password:*" { send "senha\r" expect \"*#*\"}} ssh root@$loja expect \"*password:*\"... (4 Replies)
Discussion started by: hrenechen
4 Replies

5. Shell Programming and Scripting

Spawn sftp and Shell commands

Hi everyone, I'm no killer in shell scripting, that is why I've searched and found a little script that explained how to do what I wanted to do : a FTP transfer from distant servers. I adapted it cause as such, it didn't work. As I needed to do some very simple shell commands (erase and... (2 Replies)
Discussion started by: mederik
2 Replies

6. Shell Programming and Scripting

Using spawn and expect getting error

#!/bin/sh # # set -x stty -echo; read -p "Input password:" A; stty echo; echo; for HOST in `cat elc.hosts.list` do # echo "Connecting to $HOST" expect -c "set timeout -1;\ spawn sshr $HOST -l root \"mkdir /perfstat;\";\ match_max 100000;\ expect *'/root/.ssh/id_dsa':*;\ send --... (1 Reply)
Discussion started by: madlot
1 Replies

7. Shell Programming and Scripting

Can 'spawn' command be used more than once in an expect script ?

Can 'spawn' script be used more than once in a given expect script ?? What I'm trying to do is, first log-into a remote server through one 'ssh' spawn com and then from there log-into another server using a secod 'ssh' spawn command. But this approach is not working... the second ssh attempt... (1 Reply)
Discussion started by: clakkad
1 Replies

8. Shell Programming and Scripting

Expect Script Error invalid spawn id (6)

Hi everybody, We are trying to connect to a server and to a router using an .expect script that automatically authenticate the username and password needed. The error is that we cannot connect to the server using ssh AND we cannot connect to the router using either telnet or go commands from the... (1 Reply)
Discussion started by: omoyne
1 Replies

9. Shell Programming and Scripting

Expect: How to read buffer for spawn

Hi All, I have to write one expect script to login to one system. I am using set timeout -1 match_max 100000 spawn ssh root@hostname Now when I do spawn ssh to that host it send some warning message and one challenge Challenge: 111-2345 I need to read this challenge value and has... (1 Reply)
Discussion started by: Lokesh Agrawal
1 Replies

10. Shell Programming and Scripting

Expect: Beginner help with spawn and expect

Hello hello, did a quick search and didn't turn up anything helpful. I've got a book I'm sure has the answers, but I don't think I'll have time to finish it before this all has to work, so here goes~ if this isn't a good place to post and someone could direct me to another forum I'd appreciate... (1 Reply)
Discussion started by: Vryali
1 Replies
Login or Register to Ask a Question