[Twisted-Python] telnet client code
I have this snippet running in it's own thread, and would like to port it to twisted, my program is using it anyway. Any hints how to get started? Thanks, Thomas import telnetlib, time, socket try: tn = telnetlib.Telnet(host) except socket.error, detail: print "reboot failed", host, detail return tn.read_until("Username: ") tn.write("tel\r\n") tn.read_until("Password: ") tn.write("tel\r\n") time.sleep(1) tn.read_some() tn.write("reboot\r\n") time.sleep(1)
Not sure if this is the place to post this, but twistedmatrix.com is down. Got an error about not being able to access distributed server. -JJ
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, May 8, 2003, at 07:23 AM, Justin Johnson wrote:
Not sure if this is the place to post this, but twistedmatrix.com is down. Got an error about not being able to access distributed server.
What specific URL is down? "/" certainly shouldn't be taking you to a distributed server. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+ulGbvVGR4uSOE2wRAs2ZAJ4mHiROYe2biwXinpREdvOV4HxYiQCeMaMO BvWpBWNOze50h9Y+oozAI/s= =w5rT -----END PGP SIGNATURE-----
twistedmatrix.com just wasn't coming up, while http://twistedmatrix.com/users/z3p.twistd/ gives me the error Unable to connect to distributed server. Sorry, I was mixing results and urls. :-( In any event, the main site is up again, although a little slow. Thanks. -Justin On Thu, 8 May 2003 07:46:11 -0500, "Glyph Lefkowitz" <glyph@twistedmatrix.com> said:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Thursday, May 8, 2003, at 07:23 AM, Justin Johnson wrote:
Not sure if this is the place to post this, but twistedmatrix.com is down. Got an error about not being able to access distributed server.
What specific URL is down? "/" certainly shouldn't be taking you to a distributed server. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin)
iD8DBQE+ulGbvVGR4uSOE2wRAs2ZAJ4mHiROYe2biwXinpREdvOV4HxYiQCeMaMO BvWpBWNOze50h9Y+oozAI/s= =w5rT -----END PGP SIGNATURE-----
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On 8 May 2003 at 9:22, Justin Johnson wrote:
twistedmatrix.com just wasn't coming up, while http://twistedmatrix.com/users/z3p.twistd/ gives me the error Unable to connect to distributed server.
My server is back up now. Other pyr users: is there someplace I can toss a script that will restart my server after a reboot? -p -- Paul Swartz (o_ http://twistedmatrix.com/users/z3p.twistd/ //\ z3p@twistedmatrix.com V_/_ AIM: Z3Penguin
On Thursday, May 8, 2003, at 14:40 America/New_York, Paul Swartz wrote:
On 8 May 2003 at 9:22, Justin Johnson wrote:
twistedmatrix.com just wasn't coming up, while http://twistedmatrix.com/users/z3p.twistd/ gives me the error Unable to connect to distributed server.
My server is back up now.
Other pyr users: is there someplace I can toss a script that will restart my server after a reboot?
I dunno about pyr but in general on linux if you make a crontab entry that says "@reboot command" then it should run whenever the cron daemon starts. -bob
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, May 8, 2003, at 02:18 PM, Bob Ippolito wrote:
I dunno about pyr but in general on linux if you make a crontab entry that says "@reboot command" then it should run whenever the cron daemon starts.
This is the way that most UNIXes suggest doing it - however, at least on pyramid, it seems broken. I don't know if this is a debian issue or what, but I can't get _any_ of my machines to exec @reboot crontab entries. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+usnQvVGR4uSOE2wRAkSAAKCzpRj5xyTWGPG6ThCOX3j5GNeYjwCfbjAn Zn8dvigbrwsrjVxUHFofhFs= =dvLR -----END PGP SIGNATURE-----
On Thu, 2003-05-08 at 14:19, Glyph Lefkowitz wrote:
This is the way that most UNIXes suggest doing it - however, at least on pyramid, it seems broken. I don't know if this is a debian issue or what, but I can't get _any_ of my machines to exec @reboot crontab entries.
Works For Me. on pyramid, `crontab -u acapnotic -l`: @reboot /home/acapnotic/bin/startstuff.sh and it does indeed start stuff every time pyramid reboots. So cron's @reboot on your Debian machine works fine. The only problem I've had is on shutdown my twistd's don't get TERM signals, as I've mentioned before. -- The moon is first quarter, 62.8% illuminated, 8.6 days old.
In playing with this tutorial, I first tried following the text of the tutorial, but didn't find it clear enough to assemble working code quickly. Falling back to the listings/PicturePile directory, I got the sample code working, but had to rename the directory-listings.html file and image-display.html to *.xhtml files. Steve -- _ Steven H. Rogers, PhD. <_` email: steve@shrogers.com |_> Weblog http://shrogers.com/cgi-bin/pyblosxom.cgi/ | \ "A language that doesn't affect the way you think about programming is not worth knowing." - Alan Perlis
On 08 May 2003 10:10:58 +0200 Thomas Heller <theller@python.net> wrote:
I have this snippet running in it's own thread, and would like to port it to twisted, my program is using it anyway. Any hints how to get started?
I'm not sure if telnet is symmetric - if it isn't, looks like we don't have telnet client code. Even if it is, the current code needs work in order to be usable for what you want (it's one of the more ancient parts of Twisted.) So, it seems writing a telnet client protocol (with similar methods to telnetlib that return Deferreds instead of blocking?) is in order, or at least a refacor of the current telnet code. -- Itamar Shtull-Trauring http://itamarst.org/ http://www.zoteca.com -- Python & Twisted consulting
On Thu, May 08, 2003 at 12:23:18PM -0400, Itamar Shtull-Trauring wrote:
On 08 May 2003 10:10:58 +0200 Thomas Heller <theller@python.net> wrote:
I have this snippet running in it's own thread, and would like to port it to twisted, my program is using it anyway. Any hints how to get started?
I'm not sure if telnet is symmetric - if it isn't, looks like we don't have telnet client code. Even if it is, the current code needs work in order to be usable for what you want (it's one of the more ancient parts of Twisted.)
Telnet is mostly symmetric. The existing code isn't very client-friendly, though. Here's a kinda-sorta example (untested): from twisted.protocols import telnet from twisted.internet import protocol, reactor class RebootTheServer(telnet.Telnet): mode = 'WaitForUser' def connectionMade(self): # Only defined to keep parent from sending the welcome banner pass def telnet_WaitForUser(self, line): if line.startswith('Username: '): self.write(self.factory.username + '\r\n') return 'WaitForPassword' def telnet_WaitForPassword(self, line): if line.startswith('Password: '): self.write(self.factory.password + '\r\n') # Instead of this, you could do another state, # like "WaitForPrompt" or something. reactor.callLater(1, self.reboot) return 'Idling' def telnet_Idling(self, line): # La la la. pass def reboot(self): self.write('reboot\r\n') # This will make us lose our connection after the next # line is received. To lose it faster, use # self.transport.loseConnection() instead self.mode = 'Done' def connectionLost(self, reason): if self.mode != 'Done': reason.printTraceback() reactor.stop() f = protocol.ClientFactory() f.protocol = RebootTheServer f.password = 'password' f.username = 'username' # fill in host and port reactor.connectTCP(host, port, f) # Let's go reactor.run() This is the first expect-y thing I've written with Telnet, so maybe it's not the best solution, but hopefully it gets you on the right track. Jp -- #!/bin/bash ( LIST=(~/.sigs/*.sig) cat ${LIST[$(($RANDOM % ${#LIST[*]}))]} echo -- $'\n' `uptime | sed -e 's/.*m//'` ) > ~/.signature -- up 6 days, 16:38, 10 users, load average: 0.07, 0.06, 0.00
participants (9)
-
Bob Ippolito
-
Glyph Lefkowitz
-
Itamar Shtull-Trauring
-
Jp Calderone
-
Justin Johnson
-
Kevin Turner
-
Paul Swartz
-
Steven H. Rogers, PhD.
-
Thomas Heller