Re: Can someone translate a small .PY to Perl?
Thank you for the reply to my topic, not BASH wars, but does this look correct? use IO::Socket; use strict; use Time::HiRes qw( time alarm sleep ); $server_ip = 'localhost'; $server_port = 43278; $microseconds = 5_000_000; while ( ) { my $message = IO::Socket::INET-new(Proto=udp,PeerPort=$server_port,PeerAddr=$server_ ip) or die Can't make UDP socket: $@; $message-send(PyHB!); sleep ($microseconds); } -Dave Dave Gray [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] was wondering if there were a translation in PERL so I could have my Netware servers send heartbeats to the heartbeat server? Title: PyHeartbeat - detecting inactive computers Submitter: Nicola Larosa # Filename: HeartbeatClient.py Heartbeat client, sends out an UDP packet periodically import socket, time SERVER_IP = '127.0.0.1'; SERVER_PORT = 43278; BEAT_PERIOD = 5 print ('Sending heartbeat to IP %s , port %d\n' 'press Ctrl-C to stop\n') % (SERVER_IP, SERVER_PORT) while True: hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) hbSocket.sendto('PyHB', (SERVER_IP, SERVER_PORT)) if __debug__: print 'Time: %s' % time.ctime() time.sleep(BEAT_PERIOD) Checkout Socket [1] and Time::HiRes [2], both of which should be installed already, depending on what version of perl you're working with. The rest should be fairly simple to translate by following the code examples. Let us know how that works out for you. [1] http://search.cpan.org/~nwclark/perl-5.8.6/ext/Socket/Socket.pm [2] http://search.cpan.org/~jhi/Time-HiRes-1.66/HiRes.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
GMane Python wrote: Thank you for the reply to my topic, not BASH wars, but does this look correct? use IO::Socket; use strict; use Time::HiRes qw( time alarm sleep ); $server_ip = 'localhost'; $server_port = 43278; $microseconds = 5_000_000; You need to do my $server_ip ... etc with use strict; Did you even try it? or at least perl -c file.pl ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
I'm having a bit of trouble so far. The code below is what I've found on different web sites as being the functions I believe I need: use IO::Socket; use strict; use Time::HiRes qw( time alarm sleep ); while ( ) { my $message = IO::Socket::INET-new(Proto=udp,PeerPort='43278',PeerAddr='127.0.0.1') or die Can't make UDP socket: $@; $message-send(PyHB); sleep (5_000_000); } However, it doesn't register on my Python server like the Python script does. Any idea what I'm doing wrong? Thanks -Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
Yes, but I posted a wrong file. This one doesn't work at all. I have another that seems to work, but doesn't register on my Python heartbeat server. It's posted as a reply to Dave just above. Sorry about the wrong file. -Dave JupiterHost.Net [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] GMane Python wrote: Thank you for the reply to my topic, not BASH wars, but does this look correct? use IO::Socket; use strict; use Time::HiRes qw( time alarm sleep ); $server_ip = 'localhost'; $server_port = 43278; $microseconds = 5_000_000; You need to do my $server_ip ... etc with use strict; Did you even try it? or at least perl -c file.pl ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
It does not compile on Netware, but it's OK on Windows. For Netware, I copied from my Windows PC the perl/lib and perl/site directories to Netware because Sockets::IO was not found. Now, I get: Missing $ on loop variable at sys:\perl\lib/strict.pm li BEGIN failed--compilation aborted at sys:\perl\lib/IO/So BEGIN failed--compilation aborted at pyhbclt.pl line 3. Can anyone point me in a direction here with this error? Another problem I had but resolved: I thought the sleep was in microseconds, not seconds. It would work once then not again. Then I decided I had to test EVERYTHING. Thanks to all those who helped. For anyone who wants to use PYTHONS ThreadedHeartBeatServer.py by Nicola Larosa to monitor a Netware Server, the Perl port is here: #!/usr/bin/perl use IO::Socket::INET; use Time::HiRes qw( time alarm sleep ); do { my $MySocket=new IO::Socket::INET-new(Proto=udp, PeerPort=43278, PeerAddr='localhost' ) or die Can't make UDP socket: $@; $msg=PyHB; $MySocket-send($msg); sleep (5); } while (1==1); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
On Wed, 29 Dec 2004 12:50:21 -0500, GMane Python [EMAIL PROTECTED] wrote: while ( ) { That isn't doing what you expect, which (I assume) is an infinite loop. loops over @ARGV and attempts to open each arg as a file and iterate over the lines in each. I suppose it is functionally a somewhat infinite (heh) loop with no args, as it reads from STDIN until EOF. Except that it won't do anything until it can read something from STDIN. You probably want while (1) { ... } The rest looks ok at first glance, other than the variable declaration thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Can someone translate a small .PY to Perl?
Or more commonly: while :; do ... done because the : command is true. It works for me. That's the way I'd seen it done when I was learning bash. I believe the while checks the return value, not the output of the command. Just be thankful you didn't use 'cat' uselessly. There is definitely no reason to use a separate command just for a true value in a while loop. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
was wondering if there were a translation in PERL so I could have my Netware servers send heartbeats to the heartbeat server? Title: PyHeartbeat - detecting inactive computers Submitter: Nicola Larosa # Filename: HeartbeatClient.py Heartbeat client, sends out an UDP packet periodically import socket, time SERVER_IP = '127.0.0.1'; SERVER_PORT = 43278; BEAT_PERIOD = 5 print ('Sending heartbeat to IP %s , port %d\n' 'press Ctrl-C to stop\n') % (SERVER_IP, SERVER_PORT) while True: hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) hbSocket.sendto('PyHB', (SERVER_IP, SERVER_PORT)) if __debug__: print 'Time: %s' % time.ctime() time.sleep(BEAT_PERIOD) Checkout Socket [1] and Time::HiRes [2], both of which should be installed already, depending on what version of perl you're working with. The rest should be fairly simple to translate by following the code examples. Let us know how that works out for you. [1] http://search.cpan.org/~nwclark/perl-5.8.6/ext/Socket/Socket.pm [2] http://search.cpan.org/~jhi/Time-HiRes-1.66/HiRes.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
Andrew == Andrew Gaffney [EMAIL PROTECTED] writes: Andrew It works for me. That's the way I'd seen it done when I was learning Andrew bash. I believe the while checks the return value, not the output of Andrew the command. That's a bash-ism then, not The One True Shell. I was using The One True Shell in 1980. :) -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
GMane Python wrote: Hello Everyone. Whil e reading the Python Cookbook as a means of learning Python, I came across the script by Nicola Larosa. Not knowing anything about PERL, I was wondering if there were a translation in PERL so I could have my Netware servers send heartbeats to the heartbeat server? I am beginning to learn the Python language after a 10-year programming 'vacation' from my last class in college. Looking at this, I think it'll end up being a rather quick translation, but although I'm searching for translations, I'd really like to be able to just get my Netware server to send heartbeats and not take flack from my boss for 'having to learn PERL' just to get the server to send a beat packet, so that's why I'm asking for someone's help who knows the syntax of the language. Thanks! Dave Title: PyHeartbeat - detecting inactive computers Submitter: Nicola Larosa # Filename: HeartbeatClient.py Heartbeat client, sends out an UDP packet periodically import socket, time SERVER_IP = '127.0.0.1'; SERVER_PORT = 43278; BEAT_PERIOD = 5 print ('Sending heartbeat to IP %s , port %d\n' 'press Ctrl-C to stop\n') % (SERVER_IP, SERVER_PORT) while True: hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) hbSocket.sendto('PyHB', (SERVER_IP, SERVER_PORT)) if __debug__: print 'Time: %s' % time.ctime() time.sleep(BEAT_PERIOD) Both Perl or Python are overkill for this. This can be done with a very simple bash script. It only requires netcat. #!/bin/bash SERVER_IP=127.0.0.1 SERVER_PORT=43278 BEAT_PERIOD=5 while `/bin/true`; do echo pyHB | nc -u -q 0 $SERVER_IP $SERVER_PORT sleep ${BEAT_PERIOD}s done -- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
S. David Rose wrote: Sorry, sir. I did not state it boldly enough, but this is to be used on a Netware server. There is no port for Python on Netware, but PERL is available. Obviously, bash scripting will not work It's Netware 5.0 / 5.1 for my servers. Ah, sorry. I didn't catch that part. Also, reply to the list instead of the sender. -- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
Andrew == Andrew Gaffney [EMAIL PROTECTED] writes: Andrew while `/bin/true`; Uh, what? Execute /bin/true, take its output if its output is non-null, continue. Last I checked, /bin/true outputs nothing. :) Maybe you wanted: while true; do; ...; done Or more commonly: while :; do ... done because the : command is true. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Can someone translate a small .PY to Perl?
Randal L. Schwartz wrote: Andrew == Andrew Gaffney [EMAIL PROTECTED] writes: Andrew while `/bin/true`; Uh, what? Execute /bin/true, take its output if its output is non-null, continue. Last I checked, /bin/true outputs nothing. :) Maybe you wanted: while true; do; ...; done Or more commonly: while :; do ... done because the : command is true. It works for me. That's the way I'd seen it done when I was learning bash. I believe the while checks the return value, not the output of the command. -- Andrew Gaffney Network Administrator Skyline Aeronautics, LLC. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response