<?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: telnet script while read in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825339#M638669</link>
    <description>&lt;P&gt;&amp;gt;I just want to open up the "pipe" and collect the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any interaction?&amp;nbsp; If so, then possibly use expect, unless there is some simple fixed input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;telnet $switch $port &amp;lt; /dev/null &amp;gt;/var/isnms/$host/$log 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course this never stops unless you kill it.&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2012 22:05:14 GMT</pubDate>
    <dc:creator>Dennis Handly</dc:creator>
    <dc:date>2012-10-05T22:05:14Z</dc:date>
    <item>
      <title>telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824797#M638661</link>
      <description>&lt;P&gt;I have a flat file with multiple lines of IP &amp;nbsp;PORT.&lt;/P&gt;&lt;P&gt;I am reading the flat file to telnet to the IP and PORT and log the session.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are not interactive ports so as soon as I connect I get raw data coming that I need to log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For some reason I can not get this to work.&lt;/P&gt;&lt;P&gt;I need to open a telnet to each line and continue collecting the data.&lt;/P&gt;&lt;P&gt;Question, on connection, will it move onto the next one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;exec &amp;lt; /var/isnms/switch.ip&lt;BR /&gt;while read switch port host log; do&lt;/P&gt;&lt;P&gt;if [ -d /var/isnms/$host ]&lt;BR /&gt;then&lt;BR /&gt;echo $host exist&lt;BR /&gt;else&lt;BR /&gt;mkdir /var/isnms/$host&lt;BR /&gt;fi&lt;/P&gt;&lt;P&gt;if [ -f /var/isnms/$host/$log ]&lt;BR /&gt;then&lt;BR /&gt;echo $log exist&lt;BR /&gt;echo "telnet $switch $port"&lt;BR /&gt;telnet $switch $port &amp;gt;/var/isnms/$host/$log&lt;BR /&gt;else&lt;BR /&gt;touch /var/isnms/$host/$log&lt;BR /&gt;echo "telnet $switch $port"&lt;BR /&gt;telnet $switch $port &amp;gt;/var/isnms/$host/$log&lt;BR /&gt;fi&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 05:35:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824797#M638661</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2012-10-05T05:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824833#M638662</link>
      <description>&lt;P&gt;Hi Ratzie,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so far, I can not see a big error in your script. Can you post the logging of the script? include a set -x on top ov the script and send the a log.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You check, whether the directorie /var/isnms/$host already exists. You do not check, whether any file or link or ... wis that name exists. If so, your script will fail.&lt;/P&gt;&lt;P&gt;After your first else, you may add the following command:&lt;/P&gt;&lt;P&gt;[ /var/isnms/$host ] &amp;amp;&amp;amp; mv /var/isnms/$host /var/isnms/$host.$$.bak&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May be, this already&amp;nbsp; solves your problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bye&lt;/P&gt;&lt;P&gt;Ralf&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 07:33:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824833#M638662</guid>
      <dc:creator>Ralf Seefeldt</dc:creator>
      <dc:date>2012-10-05T07:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824881#M638663</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Answer is no&lt;/P&gt;&lt;P&gt;once your telnet command is executed the script will wait for the termination of the telnet.&lt;/P&gt;&lt;P&gt;You might get it to work by running telnet in the background.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Per&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 09:22:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824881#M638663</guid>
      <dc:creator>Per Christensen_1</dc:creator>
      <dc:date>2012-10-05T09:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824907#M638664</link>
      <description>&lt;P&gt;The problem with ssh, rlogin and most likely telnet in a while loop is that they will continue to read from stdin and eat up the data that's driving the while read loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With ssh and rlogin, there is a -n option that redirects stdin to /dev/null.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure what you are doing in your while loop with /var/isnms/switch.ip?&amp;nbsp; Is this only driving the while loop or does it also have commands to telnet?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are only proving data to the while, you shouldn't be using exec to redirect stdin.&amp;nbsp; You should redirect it directly:&lt;/P&gt;&lt;P&gt;while read foo; do&lt;/P&gt;&lt;P&gt;..&lt;/P&gt;&lt;P&gt;done &amp;lt; input-file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately I don't see a -n option to telnet but you can do the obvious:&lt;/P&gt;&lt;P&gt;telnet $switch $port &amp;lt; /dev/null &amp;gt;/var/isnms/$host/$log&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;You might get it to work by running telnet in the background.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In that case, you would have to redirect stdin and probably stderr too.&amp;nbsp; The latter to the same logfile.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 10:02:22 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5824907#M638664</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-10-05T10:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825117#M638665</link>
      <description>&lt;P&gt;Yes, I see that when I run the script it just hits the first login and stays there. It will not open up muitlple telnet sessions to each line in file.&lt;/P&gt;&lt;P&gt;I can not use ssh, since these devices do not support ssh.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just want to open up the "pipe" and collect the data.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 14:24:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825117#M638665</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2012-10-05T14:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825121#M638666</link>
      <description>&lt;P&gt;would 'expect' work?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 14:25:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825121#M638666</guid>
      <dc:creator>donna hofmeister</dc:creator>
      <dc:date>2012-10-05T14:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825131#M638667</link>
      <description>&lt;P&gt;I have used expect, but would expect open up multiple telnets for logging each ip/port.&lt;/P&gt;&lt;P&gt;How would this be coded?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 14:55:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825131#M638667</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2012-10-05T14:55:07Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825139#M638668</link>
      <description>&lt;P&gt;if the behavior for these ports is consistent, a "skeleton" expect script could be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;looking at one of my expect scripts -- there's only one spot that would need to be "customized" if i wanted to reuse it for another system -- and it's the "telnet" line ("spawn telnet &amp;lt;hard-coded system name&amp;gt;").&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if i took my working expect script and changed the hard-coded system name into a "variable" (eg, "spawn telent &amp;amp;system&amp;amp;") and saved it as my "skeleton", then i could do something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;foreach $system do&lt;/P&gt;&lt;P&gt;&amp;nbsp; change &amp;amp;system&amp;amp; to $system in expect.skel &amp;gt; /tmp/somefile&lt;/P&gt;&lt;P&gt;&amp;nbsp; run /tmp/somefile&lt;/P&gt;&lt;P&gt;end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you get the idea....i hope....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(i guess your case "system" would be "port"...but...details, details...)&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 15:11:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825139#M638668</guid>
      <dc:creator>donna hofmeister</dc:creator>
      <dc:date>2012-10-05T15:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825339#M638669</link>
      <description>&lt;P&gt;&amp;gt;I just want to open up the "pipe" and collect the data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any interaction?&amp;nbsp; If so, then possibly use expect, unless there is some simple fixed input.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;telnet $switch $port &amp;lt; /dev/null &amp;gt;/var/isnms/$host/$log 2&amp;gt;&amp;amp;1 &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course this never stops unless you kill it.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2012 22:05:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5825339#M638669</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2012-10-05T22:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: telnet script while read</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5827557#M638670</link>
      <description>&lt;P&gt;Doing&lt;/P&gt;&lt;P&gt;exec &amp;lt; /var/isnms/switch.ip&lt;/P&gt;&lt;P&gt;telnet input is also that file so first you may do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;exec 4&amp;lt; /var/isnms/switch.ip&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;while read -u 4 switch port host log; do&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then like already seen in the discussion you should have&lt;/P&gt;&lt;P&gt;telnet $switch $port &amp;lt;/dev/null &amp;gt;.......&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&lt;/P&gt;&lt;P&gt;but redirecting &amp;lt;/dev/null will send a fin, so depending on the peer, may makes telnet ends.&lt;/P&gt;&lt;P&gt;an other way is to make a very long sleep as input&lt;/P&gt;&lt;P&gt;sleep10000 | telnet&amp;nbsp; .$switch $port &amp;gt;......&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you want to pass something to telnet like a password you can also do&lt;/P&gt;&lt;P&gt;(sleep 1; echo passwd ; sleep10000) | telnet&amp;nbsp; .$switch $port &amp;gt;......&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;an other way is to launch it as a coprocess&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;exec telnet $switch $port |&amp;amp;&lt;/P&gt;&lt;P&gt;exec 5&amp;lt;&amp;amp;p 6&amp;gt;&amp;amp;p&lt;/P&gt;&lt;P&gt;cat &amp;lt;&amp;amp;5 &amp;gt;/var/isnms/$host/$log &amp;amp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you want to send something to the telnet then:&lt;/P&gt;&lt;P&gt;echo 'mypasswd' &amp;gt;&amp;amp;6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to close telnet pipes:&lt;/P&gt;&lt;P&gt;exec 5&amp;lt;&amp;amp;- 6&amp;gt;&amp;amp;-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2012 08:04:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/telnet-script-while-read/m-p/5827557#M638670</guid>
      <dc:creator>Laurent Menase</dc:creator>
      <dc:date>2012-10-09T08:04:18Z</dc:date>
    </item>
  </channel>
</rss>

