To complete my script, I would like to put a timer,
let say, I want the primary IP to be ping for 24 hrs, what
do you suggest me and than I stop anoying you : )
Brgds
5 8965
To complete my script, I would like to put a timer,
let say, I want the primary IP to be ping for 24 hrs, what
do you suggest me and than I stop annoying you : )
Brgds
I've also gotten pretty good at the whole 'site moderator' thing (ie: this new thread in your name).
It's really no annoyance. If we didn't enjoy this forum and the work entailed in keeping it alive and growing, we wouldn't be posting, etc. here.
Probably the best (safest) way to run a script periodically would be to schedule a task in the OS. Windows (in your case, I believe) uses the "Scheduled Tasks" applet in the Control Panel. On *nix, it's cron.
The reason for using the OS instead of a Python timer or scheduler is that the interface is guaranteed to be running even when your computer is first booted. If you would rather require that a Python script be running (it would be a great feature if you could shut down the task with out using the Task Manager (or ps)), then I could probably whip us some running examples which you could then fine tune. I strongly suggest the former solution, though.
Hi Bartonc,
I did the find the below script, to implement
a timer to ping each minute and stop in 24 hrs.
according to your script (below) where should I place
the following properly ? (did try several combinaisons but unsuc).
Or do you have a better idea ? (answer is probably yes : ) ! -
-
insert time
-
the_time = time.time()
-
start_time = the_time
-
end_time = the_time + (60*60*24) # 24 hrs
-
while the_time < end_time:
-
# insert my code here ????????????????what I put here and How??
-
time.sleep(60) # wait 60 seconds
-
the_time = time.time() # get the new time
-
-
-
-
def fil(data):
-
patt = re.compile(r'\((\d+)% loss\)')
-
patt1 = re.compile(r'(\d+.\d+.\d+.\d)')
-
-
for line in data.split('\n'):
-
-
if line.startswith("Ping statistics for"):
-
ip = patt1.search(line).group(1)
-
-
if patt.search(line):
-
loss_num = int(patt.search(line).group(1))
-
-
if loss_num >= 2 :
-
s = open('c:/tmp/myprimarylogs.xls', 'a+')
-
s.write("%s '%s'\n" % (loss_num, ip))
-
s.close()
-
# if loss >= 2, return False - then secondary IPs are pinged
-
print 'loss_num is >= 2 ', loss_num
-
return False
-
else:
-
print 'loss_num is < 2,', loss_num
-
return True
-
-
def ping(*fnames):
-
g = open(fnames[0], 'w')
-
for fn in fnames[1:]:
-
f=open(fn, 'r')
-
ipList = [line.strip() for line in f.readlines()]
-
f.close()
-
resList = []
-
for ipAdd in ipList:
-
pingaling =os.popen("ping %s" %(ipAdd),"r")
-
data = pingaling.read()
-
resList.append(data)
-
# if loss > 2, ping secondary IPs
-
proceed = fil(data)
-
if proceed:
-
break
-
g.write('/n'.join(resList))
-
if proceed:
-
break
-
g.close()
-
-
def get_IPs(fnP, fnS):
-
while True:
-
ipAddP = raw_input("# Enter Primary IP: ")
-
if validIP(ipAddP):
-
f = open(fnP, 'w')
-
f.write(ipAddP.strip() + "\n")
-
f.close()
-
break
-
else:
-
print "Invalid IP."
-
ipList = []
-
while True:
-
while True:
-
ipAddS = raw_input("# Enter Secondary IP: ")
-
if validIP(ipAddS):
-
ipList.append(ipAddS.strip())
-
break
-
else:
-
print "Invalid IP"
-
s = raw_input("# Enter another IP? Y/N: " )
-
if s.upper() == "N":
-
f = open(fnS, 'w')
-
f.write('\n'.join(ipList))
-
f.close()
-
break
-
-
fnP = 'c:/tmp/primaryip.xls'
-
fnS = 'c:/tmp/secip.xls'
-
fnW = 'c:/tmp/workfile.txt'
-
-
get_IPs(fnP, fnS)
-
ping(fnW, fnP, fnS)
-
-
-
Loads of code
something like: -
#!/usr/bin/env python
-
# coding: UTF-8
-
-
import time
-
import re
-
import whateverelse
-
-
fnP = 'c:/tmp/primaryip.xls'
-
fnS = 'c:/tmp/secip.xls'
-
fnW = 'c:/tmp/workfile.txt'
-
-
def fil(data):
-
......
-
-
def ping(*fnames):
-
......
-
-
def get_IPs(fnP, fnS):
-
......
-
-
def main():
-
the_time = time.time()
-
start_time = the_time # Youre not using start_time at all btw.
-
end_time = the_time + (60*60*24) # 24 hrs
-
while the_time < end_time:
-
get_IPs(fnP, fnS)
-
ping(fnW, fnP, fnS)
-
time.sleep(60) # wait 60 seconds
-
the_time = time.time() # get the new time
-
-
-
if __name__ == "__main__":
-
main()
-
perhaps? Not many other ways of doing it.
Hi,
tks for your reply,
I did try your script but it
stop to :
# Enter Primary IP:
Hi,
tks for your reply,
I did try your script but it
stop to :
# Enter Primary IP:
Sorry to say it but your code makes no sense at all.
You use several functions that are never defined somwhere.
But i do know that this part: -
-
end_time = the_time + (60*60*24) # 24 hrs
-
while the_time < end_time:
-
get_IPs(fnP, fnS)
-
ping(fnW, fnP, fnS)
-
is 'wrong' and shuld be this: -
-
end_time = the_time + (60*60*24) # 24 hrs
-
get_IPs(fnP, fnS)
-
while the_time < end_time:
-
ping(fnW, fnP, fnS)
-
<rant>
WO! THERE IS A SLIMY LITTLE BUG IN THE CODE-TAGGS!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brandon J. Van Every |
last post by:
What's better about Ruby than Python? I'm sure there's something. What is
it?
This is not a troll. I'm language shopping and I want people's answers. I
don't know beans about Ruby or have...
|
by: Brandon J. Van Every |
last post by:
I'm realizing I didn't frame my question well.
What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump
up in your chair and scream "Wow! Ruby has *that*? That is SO...
|
by: Derek Fountain |
last post by:
Does Python have a timer mechanism? i.e. an "after 500 milliseconds, run
this bit of code" sort of thing?
|
by: Jonas Kölker |
last post by:
Hello.
I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of
a second. I've browsed through the library reference of python.org, but I
didn't find anything that struck me as...
|
by: Reed L. O'Brien |
last post by:
I see rotor was removed for 2.4 and the docs say use an AES module
provided separately... Is there a standard module that works alike or
an AES module that works alike but with better encryption?...
|
by: Harro de Jong |
last post by:
(absolute beginner here, sorry if this seems basic)
Section 7.10 of 'How to Think Like a Computer Scientist' contains this
discussion of string.find and other string functions:
(quote)
We can...
|
by: John Salerno |
last post by:
My code is below. The main focus would be on the OnStart method. I want
to make sure that a positive integer is entered in the input box. At
first I tried an if/else clause, then switched to...
|
by: Thomas Ploch |
last post by:
Hello folks,
I am having troubles with implementing a timed queue. I am using the
'Queue' module to manage several queues. But I want a timed access, i.e.
only 2 fetches per second max. I am...
|
by: DaTurk |
last post by:
Hi,
I'm creating an application that will need to use a timer to do a
static method call every second. My question, is what would be the
best timer to use? I know there are several, but I'd...
|
by: Robin Becker |
last post by:
I've just been testing out Jakob Sievers' speedup of Python 2.5.2 by
compiling on freebsd with gcc-4.3.3 (the standard freebsd 6.1 gcc is 3.4.4).
I'm glad to say that his modification did improve...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |