Or if you don't have netcat or expect install, you could always do something like:<br><br>#!/bin/bash<br>( echo jump mythgallery;<br> echo exit;<br>) | telnet $hostname 6546<br>exit 0;<br><br> --Matt<br><br><div class="gmail_quote">
On Jan 22, 2008 7:18 PM, Florin Andrei <<a href="mailto:florin@andrei.myip.org">florin@andrei.myip.org</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Steve Peters - Priority Electronics wrote:<br></div><div class="Ih2E3d">> ------------------------------------------<br>> #!/bin/bash<br>> telnet mythtv-frontend 6546<br>> jump mythgallery<br>
> exit<br>> exit 0<br>> ------------------------------------------<br>> The idea with that above script is that it just changes my mythfrontend<br>> to open the gallery then exit telnet and then exit the script...it
<br>> didn't work.<br><br></div>What you're looking for is a package called expect. It comes with all<br>Linux distros I'm aware of. It can be used to record and "play back" any<br>interactive session - telnet, ftp, ssh, you name it. The recording part
<br>is done by a utility called autoexpect, which creates a .exp script.<br>Then you just replay the .exp script with expect.<br><br>For some weird reason, in Ubuntu autoexpect is part of the expect-dev<br>package, and even then it's not in the $PATH, but it's in
<br>/usr/share/doc/expect-dev/examples/autoexpect.gz - somebody was smoking<br>a lot of bad stuff when they put together the package.<br>On Fedora / Red Hat / CentOS autoexpect is part of the normal expect<br>package and is in $PATH.
<br><br>After you generate the .exp script, feel free to edit the "expect"<br>statements, especially if they're "expect -exact" - usually you only<br>need the tail end of the whole string - e.g. do not expect for 25 lines
<br>of output, but only for the return of the prompt at the end.<br>That's the only bit of advice that you really need with autoexpect.<br><br><br><br>Here's a .exp file that records "telnet <a href="http://google.com" target="_blank">
google.com</a> 80":<br><br>#!/usr/bin/expect -f<br>#<br># This Expect script was generated by autoexpect on Tue Jan 22 16:09:33 2008<br># Expect and autoexpect were both written by Don Libes, NIST.<br>#<br># Note that autoexpect does not guarantee a working script. It
<br># necessarily has to guess about certain things. Two reasons a script<br># might fail are:<br>#<br># 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,<br># etc.) and devices discard or ignore keystrokes that arrive "too
<br># quickly" after prompts. If you find your new script hanging up at<br># one spot, try adding a short sleep just before the previous send.<br># Setting "force_conservative" to 1 (see below) makes Expect do this
<br># automatically - pausing briefly before sending each character. This<br># pacifies every program I know of. The -c flag makes the script do<br># this in the first place. The -C flag allows you to define a<br># character to toggle this mode off and on.
<br><br>set force_conservative 0 ;# set to 1 to force conservative mode even if<br> ;# script wasn't run conservatively originally<br>if {$force_conservative} {<br> set send_slow {1 .1}
<br> proc send {ignore arg} {<br> sleep .1<br> exp_send -s -- $arg<br> }<br>}<br><br>#<br># 2) differing output - Some programs produce different output each time<br># they run. The "date" command is an obvious example. Another is
<br># ftp, if it produces throughput statistics at the end of a file<br># transfer. If this causes a problem, delete these patterns or replace<br># them with wildcards. An alternative is to use the -p flag (for<br># "prompt") which makes Expect only look for the last line of output
<br># (i.e., the prompt). The -P flag allows you to define a character to<br># toggle this mode off and on.<br>#<br># Read the man page for more info.<br>#<br># -Don<br><br><br>set timeout -1<br>spawn $env(SHELL)<br>match_max 100000
<br>expect -exact "]0;florin@scout: ~florin@scout:~\$ "<br>send -- "telnet <a href="http://google.com" target="_blank">google.com</a> 80\r"<br>expect -exact "telnet <a href="http://google.com" target="_blank">
google.com</a> 80\r<br>Trying 64.233.167.99...\r<br>Connected to google.com.\r<br>Escape character is '^\]'.\r<br>"<br>send -- "HEAD / HTTP/1.1\r"<br>expect -exact "HEAD / HTTP/1.1\r<br>"<br>
send -- "\r"<br>expect -exact "\r<br>HTTP/1.1 200 OK\r<br>Cache-Control: private\r<br>Content-Type: text/html; charset=ISO-8859-1\r<br>Set-Cookie:<br>PREF=ID=fd69576a5e09d550:TM=1201046993:LM=1201046993:S=p1NDq1JyrFXzBvh-;
<br>expires=Fri, 22-Jan-2010 00:09:53 GMT; path=/; domain=.google.com\r<br>Server: gws\r<br>Content-Length: 0\r<br>Date: Wed, 23 Jan 2008 00:09:53 GMT\r<br>\r<br>"<br>send -- " "<br>expect -exact "^\]\r
<br>telnet> "<br>send -- "QUIT\r"<br>expect -exact "QUIT\r<br>Connection closed.\r<br>]0;florin@scout: ~florin@scout:~\$ "<br>send -- "exit\r"<br>expect eof<br><font color="#888888"><br>
<br>--<br>Florin Andrei<br><br><a href="http://florin.myip.org/" target="_blank">http://florin.myip.org/</a><br></font><div><div></div><div class="Wj3C7c">_______________________________________________<br>mythtv-users mailing list
<br><a href="mailto:mythtv-users@mythtv.org">mythtv-users@mythtv.org</a><br><a href="http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users" target="_blank">http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users</a><br>
</div></div></blockquote></div><br>