using expect to log into devices

Scott Weeks surfer at mauigateway.com
Sat Jul 21 20:37:47 UTC 2018


--- ler762 at gmail.com wrote:
From: Lee <ler762 at gmail.com>

> I have a file with 1000s of devices and another file
> with a list of commands.  The program issues all
> commands for a device and then moves on to the next
> one using nested loops.  In the debug I see the
> "spawn_id expNN" (where NN is a number that, I
> believe is representative of the number of file
> descriptors used in the system) increment only when
> a device does not respond.  As long as a device
> responds before the timeout period I see the expNN
> number does not increase.  As soon as a device
> doesn't respond the expNN count goes up and I can't
> figure out why.  Once I hit a certain expNN the
<snip>

:: 'close $spawn_id' is wrong, so maybe that's it?

:: man expect
:: close [-slave] [-onexec 0|1] [-i spawn_id]
:: closes  the  connection to the current process.  
:: ...  The -i
:: flag declares the
:: process to close corresponding to the named 
:: spawn_id.
   <.. snip ..>
----------------------------------------

I hand typed the close stuff in the email with just
'close spawn_id'.  I did the -i in previous 
iterations, but saw no difference.  Maybe I should 
try more.  I saw the 'close' alone a lot on 
Stackexchange a lot,so I was copying those in this 
iteration.  I also should have read the man page 
more than I did, so a face slap to myself.


:: No  matter  whether  the connection is closed 
:: implicitly or explicitly, you should call wait to 
:: clear up the corresponding kernel process slot.  
:: close does not call wait since there is no guarantee 
:: that closing a process connection will cause it to 
:: exit.  See wait below for more info.

:: The eof and timeout cases are basically
::  { catch {close}; catch {wait}; }

I always used wait after close and need to look into 
those above.  Maybe they close it different somehow.


:: get rancid from here... and take a look at clogin...

I'm going to be looking for a new job and want to up my 
skills, in case I get a chance to do the SDN/NFV stuff, 
which I read requires coding skills, so this is also an 
exercise toward that.  Plus it's fun.

I had already done this in PERL, but, even though we 
have PERL, we are not allowed to download modules here.  
So, I'm redoing it in Expect.  I thought someone would
say a "oh just <blah, blah> and you're done" type of 
response.

Thanks a lot from everyone private and on the list.
I'll post for the archives if I find the answer.

scott




More information about the NANOG mailing list