<?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 in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023502#M74068</link>
    <description>me copy pasted a snippet from one of my monitor scripts :-D&lt;BR /&gt;-balaji</description>
    <pubDate>Tue, 15 Jul 2003 03:05:21 GMT</pubDate>
    <dc:creator>Balaji N</dc:creator>
    <dc:date>2003-07-15T03:05:21Z</dc:date>
    <item>
      <title>Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023498#M74064</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;Can anyone show me a sample script that can automatically telnet into another server and execute another script within that server.&lt;BR /&gt;&lt;BR /&gt;I need to create one and pattern it from your sample.&lt;BR /&gt;&lt;BR /&gt;Thanks as I don't have any scripting skills whatsoever.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 15 Jul 2003 02:34:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023498#M74064</guid>
      <dc:creator>Kenneth_18</dc:creator>
      <dc:date>2003-07-15T02:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023499#M74065</link>
      <description>If it's just to execute one command, you might be better served setting up remote equivalency (either using ssh (as has been discussed in previous threads), or using rsh).&lt;BR /&gt;&lt;BR /&gt;If it does need to be 'telnet', then it's easiest (or perhaps more stable) to use expect.&lt;BR /&gt;&lt;BR /&gt;Most modern linux distributions would come with Expect.&lt;BR /&gt;&lt;BR /&gt;A simple expect script could be something like:&lt;BR /&gt;&lt;BR /&gt;---------------------------------------#!/usr/bin/expect&lt;BR /&gt;&lt;BR /&gt;set timeout -1&lt;BR /&gt;&lt;BR /&gt;spawn /usr/bin/telnet&lt;BR /&gt;&lt;BR /&gt;expect "login:"&lt;BR /&gt;send "&lt;USERNAME&gt;\r"&lt;BR /&gt;expect "password:"&lt;BR /&gt;send "&lt;PASSWORD&gt;\r"&lt;BR /&gt;expect "]$"&lt;BR /&gt;send "yourcommand\r"&lt;BR /&gt;expect "]$"&lt;BR /&gt;---------------------------------------&lt;BR /&gt;&lt;BR /&gt;The man page for Expect can tell you more.&lt;BR /&gt;&lt;BR /&gt;You can truely do some amazing stuff with expect..  A bit of TCl knowledge and you're laughing ;)&lt;/PASSWORD&gt;&lt;/USERNAME&gt;</description>
      <pubDate>Tue, 15 Jul 2003 02:57:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023499#M74065</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2003-07-15T02:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023500#M74066</link>
      <description>install expect.&lt;BR /&gt;&lt;BR /&gt;+++++++++++++++cut here+++++++++++++++++++++++&lt;BR /&gt;#!/usr/bin/expect -f&lt;BR /&gt;#&lt;BR /&gt;# This script telnets to a specific host as a specifc user and sets the required&lt;BR /&gt;# environment variables.&lt;BR /&gt;&lt;BR /&gt;#Change default timeout&lt;BR /&gt;set timeout 100&lt;BR /&gt;&lt;BR /&gt;#Variables. Change as necessary&lt;BR /&gt;set TERM xterm                          ;#default TERM&lt;BR /&gt;set prompt "(%|#|\\$) $"                ;# default prompt&lt;BR /&gt;catch {set prompt $env(EXPECT_PROMPT)}&lt;BR /&gt;&lt;BR /&gt;#Host Name&lt;BR /&gt;set SERVER "[lrange $argv 0 0]"&lt;BR /&gt;set USER "[lrange $argv 1 1]"&lt;BR /&gt;set PASSWD "[lrange $argv 2 2]"&lt;BR /&gt;&lt;BR /&gt;#Command List&lt;BR /&gt;set COMMANDS "[lrange $argv 3 $argc]"&lt;BR /&gt;&lt;BR /&gt;#Spawn Telnet&lt;BR /&gt;spawn telnet&lt;BR /&gt;expect  "telnet&amp;gt; "&lt;BR /&gt;&lt;BR /&gt;#Initialise a Connection&lt;BR /&gt;send "open $SERVER\r"&lt;BR /&gt;&lt;BR /&gt;#Login to the Server&lt;BR /&gt;expect {&lt;BR /&gt;        -re "Connection timed out" {&lt;BR /&gt;                send_user "Unable to connect to $host. Exiting..."&lt;BR /&gt;                exit 1&lt;BR /&gt;                }&lt;BR /&gt;        timeout {&lt;BR /&gt;                send_user "Timed out connecting to $host. Exiting..."&lt;BR /&gt;                exit 1&lt;BR /&gt;                }&lt;BR /&gt;        "login* "&lt;BR /&gt;        }&lt;BR /&gt;send "$USER\r"&lt;BR /&gt;expect "Password:*"&lt;BR /&gt;send "$PASSWD\r"&lt;BR /&gt;&lt;BR /&gt;expect {&lt;BR /&gt;        -re "Login incorrect*" {&lt;BR /&gt;                send_user "Looks like the password is wrong. Spawning a shell..."&lt;BR /&gt;                interact&lt;BR /&gt;                exit 1&lt;BR /&gt;        }&lt;BR /&gt;        -re $prompt&lt;BR /&gt;        }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#loop through arguments&lt;BR /&gt;foreach command  $COMMANDS {&lt;BR /&gt;        send "$command\r"&lt;BR /&gt;        expect -re $prompt&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;send_user "Expect Scripts Ends. Good Bye!!!\n"&lt;BR /&gt;+++++++++++++++cut here+++++++++++++++++++++++&lt;BR /&gt;&lt;BR /&gt;call this script as &lt;BR /&gt;&lt;BR /&gt;scriptname servername username password command[s]&lt;BR /&gt;&lt;BR /&gt;and, if you want to have a basic script and then work out from there, check out autoexpect.&lt;BR /&gt;snipped below is from the man page of autoexpect.&lt;BR /&gt;++++++++++++++++++++++++++++++++++++++++++++++&lt;BR /&gt;AUTOEXPECT(1)                                       AUTOEXPECT(1)&lt;BR /&gt;&lt;BR /&gt;NAME&lt;BR /&gt;       autoexpect - generate an Expect script from watching a session&lt;BR /&gt;&lt;BR /&gt;SYNOPSIS&lt;BR /&gt;       autoexpect [ args ] [ program args...  ]&lt;BR /&gt;&lt;BR /&gt;INTRODUCTION&lt;BR /&gt;       autoexpect  watches  you  interacting  with  another  program  and creates an Expect script that reproduces your interactions.  For&lt;BR /&gt;       straightline scripts, autoexpect saves substantial time over writing scripts by hand.  Even if you are an Expect expert,  you  will&lt;BR /&gt;       find  it convenient to use autoexpect to automate the more mindless parts of interactions.  It is much easier to cut/paste hunks of&lt;BR /&gt;       autoexpect scripts together than to write them from scratch.  And if you are a beginner, you may be able to get away with  learning&lt;BR /&gt;       nothing more about Expect than how to call autoexpect.&lt;BR /&gt;&lt;BR /&gt;++++++++++++++++++++++++++++++++++++++++++++++&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;hth&lt;BR /&gt;-balaji</description>
      <pubDate>Tue, 15 Jul 2003 02:58:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023500#M74066</guid>
      <dc:creator>Balaji N</dc:creator>
      <dc:date>2003-07-15T02:58:35Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023501#M74067</link>
      <description>*chuckle* balaji's is a bit more thorough :P&lt;BR /&gt;&lt;BR /&gt;and mine was missing (at the very least) a ' --' on the fisrt line..</description>
      <pubDate>Tue, 15 Jul 2003 03:00:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023501#M74067</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2003-07-15T03:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023502#M74068</link>
      <description>me copy pasted a snippet from one of my monitor scripts :-D&lt;BR /&gt;-balaji</description>
      <pubDate>Tue, 15 Jul 2003 03:05:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023502#M74068</guid>
      <dc:creator>Balaji N</dc:creator>
      <dc:date>2003-07-15T03:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023503#M74069</link>
      <description>pls zero point this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;to add to that Stuart, one thing i have mastered from Windows is the art of Ctrl+C and Ctrl+V&lt;BR /&gt;-balaji</description>
      <pubDate>Tue, 15 Jul 2003 03:08:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023503#M74069</guid>
      <dc:creator>Balaji N</dc:creator>
      <dc:date>2003-07-15T03:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023504#M74070</link>
      <description>:)  I still use ctrl-ins (copy)/shift-ins (paste).  Old-school Windows hang-over :)&lt;BR /&gt;&lt;BR /&gt;The expect routine we use for stuff like that is a little more complex.. about 5kb back-ended with a PHP script (7kb) and an Interbase database (1.2mb) with all the hosts and authentication details of our various client sites..  Much fun ;)&lt;BR /&gt;&lt;BR /&gt;The above was vaguely copied from the quick-hack routine :P&lt;BR /&gt;&lt;BR /&gt;0pts here too pls.</description>
      <pubDate>Tue, 15 Jul 2003 03:21:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023504#M74070</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2003-07-15T03:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023505#M74071</link>
      <description>I use expect to automate my telnet sesssions...&lt;BR /&gt;&lt;BR /&gt;I'm attaching a script&lt;BR /&gt;&lt;BR /&gt;all you need to do is change your username and your password and the servername</description>
      <pubDate>Tue, 15 Jul 2003 10:11:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023505#M74071</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2003-07-15T10:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023506#M74072</link>
      <description>Hello!&lt;BR /&gt;&lt;BR /&gt;After install of expect&lt;BR /&gt;use this script&lt;BR /&gt;&lt;BR /&gt;Caesar</description>
      <pubDate>Tue, 15 Jul 2003 18:29:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023506#M74072</guid>
      <dc:creator>Caesar_3</dc:creator>
      <dc:date>2003-07-15T18:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023507#M74073</link>
      <description>I was trying to use the script&lt;BR /&gt;expect {&lt;BR /&gt;timeout { exit 1 }&lt;BR /&gt;"login*"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;keep getting error &lt;BR /&gt;invalid command name "&lt;BR /&gt;timeout { &lt;BR /&gt;exit 1 &lt;BR /&gt;}&lt;BR /&gt;"login: "&lt;BR /&gt;"&lt;BR /&gt;&lt;BR /&gt;Another question is about match_max, set timeout; when there are a large amount of data coming from the remote server which size is larger than match_max and the time is longer than the timeout, the script exit at timeout interval which is unexpected.&lt;BR /&gt;&lt;BR /&gt;Could anybody help on this?&lt;BR /&gt;&lt;BR /&gt;Many Thanks!</description>
      <pubDate>Fri, 19 Sep 2003 14:31:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023507#M74073</guid>
      <dc:creator>Yan LI_4</dc:creator>
      <dc:date>2003-09-19T14:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023508#M74074</link>
      <description>I use expect to telnet out to other servers (linux and HP-UX)  it is fantastic and can be found here: &lt;A href="http://expect.nist.gov/" target="_blank"&gt;http://expect.nist.gov/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;it's SOOOOO easy to use.</description>
      <pubDate>Mon, 22 Sep 2003 13:56:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023508#M74074</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2003-09-22T13:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Telnet Script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023509#M74075</link>
      <description>sorry for the double post (the one above)&lt;BR /&gt;no points for that one please&lt;BR /&gt;&lt;BR /&gt;one nice thing about expect is that it has a build it script writter called autoexpect&lt;BR /&gt;&lt;BR /&gt;if you are having errors you can use autoexpect to automatically generate a script for you.&lt;BR /&gt;&lt;BR /&gt;just type:&lt;BR /&gt;autoexpect -f filename telnet servername&lt;BR /&gt;&lt;BR /&gt;and proceed to log in&lt;BR /&gt;once you are done hit Ctrl D (or Ctrl C - i can't remember which) and expect will write a script of your session to "filename" you specified in your command line.  edit that file and remove some of the unnecessary lines and you'll be all set</description>
      <pubDate>Mon, 22 Sep 2003 14:37:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/telnet-script/m-p/3023509#M74075</guid>
      <dc:creator>John Meissner</dc:creator>
      <dc:date>2003-09-22T14:37:44Z</dc:date>
    </item>
  </channel>
</rss>

