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>




Reply via email to