[NTLUG:Discuss] Scripting help
Leroy Tennison
leroy.tennison at verizon.net
Mon Oct 13 20:41:36 CDT 2014
I hadn't thought about expect even though I've used it before, thanks.
Now the question is "Is it installed on the Linux machine i have to use?"
On 10/13/2014 12:17 PM, Dave Jones wrote:
> On Fri, Oct 10, 2014 at 11:06 PM, Leroy Tennison
> <leroy.tennison at verizon.net> wrote:
>> Well, interesting result, it obviously did telnet to the devices (got Trying
>> .., Connected to..., Escape character is ..) but then "Connection closed by
>> foreign host." before ever showing me the login screen (three times, once
>> for each device in my list). BTW, I'm discovering that things which work on
>> bash in SuSE 12.2 (bash 4.2.45(1)) don't work on RHEL 5 (bash 3.2.25(1)).
>>
>> On 10/09/2014 09:13 PM, Christopher Cox wrote:
>>> On 09/24/2014 10:24 PM, Leroy Tennison wrote:
>>>> I'm trying to get telnet to repetitively connect to a newline-delimited
>>>> list of
>>>> devices. In other words, if I have device1, device2 and device3 then
>>>> what I
>>>> want is:
>>>>
>>>> telnet device1
>>>> telnet device2
>>>> telnet device3
>>>>
>>> xargs -n1 telnet <<HERE
>>> device1
>>> device2
>>> device3
>>> ...
>>> deviceN
>>> HERE
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> http://www.ntlug.org/mailman/listinfo/discuss
>>>
>>
>> _______________________________________________
>> http://www.ntlug.org/mailman/listinfo/discuss
> Have you tried expect? I have a very complex script that telnet's
> into Cisco routers
> all over the country and does pings to various places then puts the
> output into a CSV
> file for easy import into a report spreadsheet.
>
> You may have to do a bit of trial-and-error from the command line with
> expect to the
> devices but once you get that part figured out, wrap a while loop around it.
>
> while read DEVICE; do
> expect << EOF
> spawn telnet $DEVICE
> expect "Username:"
> send "blah"
> (continue expect commands...)
> send "exit"
> exit
> EOF
> done < inputfile
>
> inputfile is a list of the devices each on their own line.
>
> Dave
>
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
>
More information about the Discuss
mailing list