<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Automating a Telnet Session in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588278#M32523</link>
    <description>Mark,&lt;BR /&gt;&lt;BR /&gt;As pointed by Herves, sleep is very important.&lt;BR /&gt;Try like this&lt;BR /&gt;&lt;BR /&gt;(sleep 5                    &lt;BR /&gt;echo password               &lt;BR /&gt;sleep 5                     &lt;BR /&gt;echo show ip nat trans &lt;BR /&gt;sleep 15 &lt;BR /&gt;echo exit) |telnet $IP_Address&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
    <pubDate>Tue, 02 Oct 2001 15:26:26 GMT</pubDate>
    <dc:creator>Sridhar Bhaskarla</dc:creator>
    <dc:date>2001-10-02T15:26:26Z</dc:date>
    <item>
      <title>Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588274#M32519</link>
      <description>I've been asked to write a script to periodically logs into our router and captures the NAT table info.  &lt;BR /&gt;&lt;BR /&gt;Here's an excerpt of what I'm having problems with:&lt;BR /&gt;&lt;BR /&gt;(echo "password";echo "show ip nat trans";sleep 30) | telnet $IP_ADDRESS &amp;gt; $DIR/info.$TAG&lt;BR /&gt;&lt;BR /&gt;Basically I thought this would echo the router password (yeah I know it's clear text) and router command piping them through telnet and redirect the output to a file.&lt;BR /&gt;&lt;BR /&gt;What happens though is that I seem to get to the router (it responds with the expected prompt, but it's as if I'm not really logged in.  I cannot issue any commands to it.&lt;BR /&gt;&lt;BR /&gt;Even if I just try on the command line to pipe the password to the telnet session it appears to log in but I cannot type any commands.&lt;BR /&gt;&lt;BR /&gt;Is there something I'm doing wrong in trying to initiate this telnet session?  &lt;BR /&gt;&lt;BR /&gt;I thought about Expect but was hoping to avoid the addition of another piece of software.  Are there other ways to automate telnet sessions?&lt;BR /&gt;&lt;BR /&gt;Thanks much,&lt;BR /&gt;&lt;BR /&gt;-mark&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Oct 2001 14:28:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588274#M32519</guid>
      <dc:creator>Mark Sellan</dc:creator>
      <dc:date>2001-10-02T14:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588275#M32520</link>
      <description>I would highly recommend expect for this. This is exactly the type of thing that expect is good at.</description>
      <pubDate>Tue, 02 Oct 2001 14:53:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588275#M32520</guid>
      <dc:creator>Bernie Vande Griend</dc:creator>
      <dc:date>2001-10-02T14:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588276#M32521</link>
      <description>Hi Mark:&lt;BR /&gt;&lt;BR /&gt;Try 'remsh' or 'rexec', as for instance:&lt;BR /&gt;&lt;BR /&gt;# remsh thehost -l root -n "(date;hostname;pwd) &amp;gt; /tmp/result"&lt;BR /&gt;&lt;BR /&gt;...which would place the output of the commands into /tmp/result on 'thehost', and then:&lt;BR /&gt;&lt;BR /&gt;# remsh thehost -l root -n "cat /tmp/result"&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 02 Oct 2001 15:09:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588276#M32521</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-10-02T15:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588277#M32522</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;I think it's better to use expect, but you can&lt;BR /&gt;try with telnet. Don't forget to add a sleep &lt;BR /&gt;between each stage of connection :&lt;BR /&gt;&lt;BR /&gt;#!/bin/sh&lt;BR /&gt;# Wait login prompt&lt;BR /&gt;sleep 5&lt;BR /&gt;echo $LOGIN&lt;BR /&gt;# Wait passwd prompt&lt;BR /&gt;sleep 5&lt;BR /&gt;echo $PASSWD&lt;BR /&gt;# Wait connection is established&lt;BR /&gt;echo ls&lt;BR /&gt;# Here your commands are executed (don't use sleep)&lt;BR /&gt;# Don't forget to disconnect from remote&lt;BR /&gt;echo exit&lt;BR /&gt;# At the end don't forget to quit your script&lt;BR /&gt;# after executions&lt;BR /&gt;sleep 30&lt;BR /&gt;exit&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;You need to try to find your own sleeping times.&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;&lt;BR /&gt;Herv?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Oct 2001 15:11:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588277#M32522</guid>
      <dc:creator>Herve BRANGIER</dc:creator>
      <dc:date>2001-10-02T15:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588278#M32523</link>
      <description>Mark,&lt;BR /&gt;&lt;BR /&gt;As pointed by Herves, sleep is very important.&lt;BR /&gt;Try like this&lt;BR /&gt;&lt;BR /&gt;(sleep 5                    &lt;BR /&gt;echo password               &lt;BR /&gt;sleep 5                     &lt;BR /&gt;echo show ip nat trans &lt;BR /&gt;sleep 15 &lt;BR /&gt;echo exit) |telnet $IP_Address&lt;BR /&gt;&lt;BR /&gt;-Sri&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Oct 2001 15:26:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588278#M32523</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-10-02T15:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588279#M32524</link>
      <description>Thanks so much everyone for your suggestions...unfortunately, none seem to work with the Cisco router I have to communicate with.  &lt;BR /&gt;&lt;BR /&gt;I guess I am going to have to install Expect.  Can I get this through the HP-UX Shareware site?  Are any of you using it?  I'd like to get any feedback about it you could share.&lt;BR /&gt;&lt;BR /&gt;Thanks again,&lt;BR /&gt;&lt;BR /&gt;-mark&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Oct 2001 17:20:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588279#M32524</guid>
      <dc:creator>Mark Sellan</dc:creator>
      <dc:date>2001-10-02T17:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588280#M32525</link>
      <description>Mark,&lt;BR /&gt;&lt;BR /&gt;You can get expect from this following site free.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/expect-5.31/" target="_blank"&gt;http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/expect-5.31/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You can use this sample script to get what you want.&lt;BR /&gt;&lt;BR /&gt;#!/wherever/expect -f  &lt;BR /&gt;                            &lt;BR /&gt;set prompt "(%|#|\\$|&amp;gt;)"  &lt;BR /&gt;                            &lt;BR /&gt;set timeout 10              &lt;BR /&gt;                            &lt;BR /&gt;spawn telnet $IP_ADDRESS      &lt;BR /&gt;expect "login: "            &lt;BR /&gt;send "password\r"          &lt;BR /&gt;expect "$prompt"&lt;BR /&gt;send "show ip nat trans "          &lt;BR /&gt;expect "$prompt"&lt;BR /&gt;send "exit\r"   &lt;BR /&gt;&lt;BR /&gt;You can simplify the script by replacing $prompt with the prompt of your router.&lt;BR /&gt;      &lt;BR /&gt;The above is only a template. May not work.&lt;BR /&gt;&lt;BR /&gt;-Sri</description>
      <pubDate>Tue, 02 Oct 2001 18:40:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588280#M32525</guid>
      <dc:creator>Sridhar Bhaskarla</dc:creator>
      <dc:date>2001-10-02T18:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588281#M32526</link>
      <description>Note, you will also need depots of tk and tcl before you install the expect depot. Both are also available from the site  Sridhar gave you:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tcl-8.2.1/" target="_blank"&gt;http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tcl-8.2.1/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tk-8.2.1/" target="_blank"&gt;http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tk-8.2.1/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;install these and then the expect depot and you'll be all set to write a script.  You should be able to find some examples at &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.scriptics.com/scripting/" target="_blank"&gt;http://www.scriptics.com/scripting/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Oct 2001 19:22:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588281#M32526</guid>
      <dc:creator>Bernie Vande Griend</dc:creator>
      <dc:date>2001-10-02T19:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588282#M32527</link>
      <description>Hi Mark,&lt;BR /&gt; If I understand correctly, you want to do the Batch Telnet I mean u want to execute some script or commands on other systems thru telnet. &lt;BR /&gt;  If you want to execute the just the script on the other system then the best way to make the Trust Relationship between the two systems and then use the remsh command. &lt;BR /&gt; If you don't want to go with this and simply want Batch Telnet then follow the steps:&lt;BR /&gt;1. You should have Perl 5.6.1 or later version install on your machine; not necessary on the other end.&lt;BR /&gt;2. Just copy this under the $PERL_HOME/site/lib/Net directory(Attached)&lt;BR /&gt;  you can find more about this at &lt;A href="http://search.cpan.org/doc/JROGERS/Net-Telnet-3.02/lib/Net/Telnet.pm" target="_blank"&gt;http://search.cpan.org/doc/JROGERS/Net-Telnet-3.02/lib/Net/Telnet.pm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;3. Write this simple perl script&lt;BR /&gt;&lt;BR /&gt;use Net::Telnet ();&lt;BR /&gt;$t = new Net::Telnet (Timeout =&amp;gt; 90,&lt;BR /&gt;         Errmode=&amp;gt;'die');&lt;BR /&gt;$t-&amp;gt;open('your hostname');&lt;BR /&gt;$t-&amp;gt;waitfor('/login: $/i');&lt;BR /&gt;$t-&amp;gt;print('your_username');&lt;BR /&gt;$t-&amp;gt;waitfor('/password: $/i');&lt;BR /&gt;$t-&amp;gt;print('your_password');&lt;BR /&gt;$t-&amp;gt;waitfor('/\$ $/i');&lt;BR /&gt;$t-&amp;gt;print('script_to_run');&lt;BR /&gt;@lines = $t-&amp;gt;waitfor('/\$ $/i');&lt;BR /&gt;print @lines;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Now just replace the above with your info.&lt;BR /&gt;your_hostname&lt;BR /&gt;your_username&lt;BR /&gt;your_password&lt;BR /&gt;script_to_run&lt;BR /&gt;&lt;BR /&gt;This will solve your problem. &lt;BR /&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;Zafar</description>
      <pubDate>Wed, 03 Oct 2001 11:26:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588282#M32527</guid>
      <dc:creator>Zafar A. Mohammed</dc:creator>
      <dc:date>2001-10-03T11:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Telnet Session</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588283#M32528</link>
      <description>Hi&lt;BR /&gt;&lt;BR /&gt;The script below shows how to send some initial commands to a router (like password) and then enter your own commands.&lt;BR /&gt;&lt;BR /&gt;router=&lt;IP_ADDRESS&gt;&lt;BR /&gt;( echo &lt;PASSWORD&gt;&lt;BR /&gt;echo &lt;CMD&gt;&lt;BR /&gt;echo &lt;CMD&gt;&lt;BR /&gt;while read cmd&lt;BR /&gt; echo $cmd&lt;BR /&gt;done&lt;BR /&gt;) | telnet $router | tee &lt;FILENAME&gt;&lt;BR /&gt;&lt;BR /&gt;You may want to sleep for a few seconds between commands but I have not needed to.&lt;BR /&gt;&lt;BR /&gt;Of course to have no input from you required, echo exit inside the brackets and remove the while loop.  The output can then be redirected to a file rather than tee'd.&lt;BR /&gt;&lt;BR /&gt;From my understanding, the reason your original script didn't work is that you were typing in was not being picked up by the script and passed on to the telnet session.&lt;BR /&gt;&lt;BR /&gt;It does not work trying to script a session to another unix host.  Any ideas on why?&lt;BR /&gt;&lt;BR /&gt;Sean&lt;/FILENAME&gt;&lt;/CMD&gt;&lt;/CMD&gt;&lt;/PASSWORD&gt;&lt;/IP_ADDRESS&gt;</description>
      <pubDate>Thu, 25 Oct 2001 00:54:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/automating-a-telnet-session/m-p/2588283#M32528</guid>
      <dc:creator>Sean Venter</dc:creator>
      <dc:date>2001-10-25T00:54:59Z</dc:date>
    </item>
  </channel>
</rss>

