1

After I scp a file using spawn, the spawn_id, exp8, closes out. gets eof. so, any other commands I run after that, I get this message: an not find channel named "exp8". So I'm assuming that once a spawn occurs, the script defaults to the latest spawn, regardless of whether it still exists or not.

Is there a way to default back to exp7? Or do I have to point out using exp7 on EVERY send and expect command?

The reason I'm asking this is because I can't seem to get scp to work by using a send command. It seems that only a spawn command of scp seems to work. The send version of it seems to just hang there and doesn't actually send the command. I have no problem using send to issue ssh commands into other servers, but it just won't work with scp. So I must use spawn. But I get this problem of trying to progress the program. The program's purpose is to log into a server, copy files from the originating server to the logged in server, then from the logged in server, log into other remote servers only accessible through this "access server" and issue install commands.

I asked this on Linux Questions, but all I get is how I need to be more detailed. So it makes me think nobody there knows the answer but they are quick to find fault with posts. I'm not asking anyone to review any code, plus I cannot post it as it's on another network that's isolated. But if anyone knows the answer to the question that would be great.

1
  • To handle timeouts, use set timeout -1 in your expect code. The $timeout variable holds a number of seconds, where -1 means "never time out" Commented Dec 21, 2018 at 21:44

1 Answer 1

1

Is there a way to default back to exp7?

As the description of spawn in the expect(1) man page says:

When a process is started by spawn, the variable spawn_id is set to a descriptor referring to that process. The process described by spawn_id is considered the current process. spawn_id may be read or written, in effect providing job control.

So:

spawn ssh ... # Save $spawn_id for later use set ssh_spawn_id $spawn_id spawn scp ... # If a password is expected... #expect assword: #send "$pass\r" # Either way, wait for SCP to finish expect eof # Now switch back to SSH set spawn_id $ssh_spawn_id ... 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.