The below script produces a '[Errno 9] Bad File Descriptor' when
executed. If I remove the try: except: statements, the script stops when
the error occurs.
The purpose of the script is to monitor the size of the three main logs
on a Windows 2003 server and send and email should any of the logs get
shorter. It works fine... just don't know *why* it produces the '[Errno
9] Bad File Descriptor' error.
I'm running Python 2.4.1 on Windows 2003 SP1 Server with no funky win32
extensions ;)
logs = ['AppEvent.Evt', 'SecEvent.Evt', 'SysEvent.Evt']
app_size = 0
sec_size = 0
sys_size = 0
def send_email(LogName, old_size, new_size):
f = "Somebody<XX*******@vt.edu>"
t = "So***********@vt.edu"
msg = MIMEText("""old_size = %d, new_size = %d""" %(old_size,
new_size))
msg["Subject"] = "%s Log Just Got Shorter" %LogName
msg["Message-id"] = email.Utils.make_msgid()
msg["From"] = f
msg["To"] = t
h = "smtp.vt.edu"
s = smtplib.SMTP(h)
s.sendmail(f, t, msg.as_string())
s.quit()
while 1:
for log in logs:
try:
a = os.stat('C:\WINDOWS\System32\config\%s' %log)
cur_size = a[6]
print log
print "cur_size", cur_size
if log == 'AppEvent.Evt':
print "old_size", app_size, "\n"
if cur_size >= app_size:
app_size = cur_size
time.sleep(6)
continue
else:
send_email(log, app_size, cur_size)
time.sleep(6)
continue
elif log == 'SecEvent.Evt':
print "old_size", sec_size, "\n"
if cur_size >= sec_size:
sec_size = cur_size
time.sleep(6)
continue
else:
send_email(log, sec_size, cur_size)
time.sleep(6)
continue
else:
print "old_size", sys_size, "\n"
if cur_size >= sys_size:
sys_size = cur_size
time.sleep(6)
continue
else:
send_email(log, sys_size, cur_size)
time.sleep(6)
continue
except Exception, e:
fp7 = file('log_mon_exception.txt', 'a')
print >> fp7, e
fp7.close() 1 2774
"rbt" <rb*@athop1.ath.vt.edu> schrieb im Newsbeitrag
news:d5**********@solaris.cc.vt.edu...
| The below script produces a '[Errno 9] Bad File Descriptor' when
| executed. If I remove the try: except: statements, the script stops when
| the error occurs.
|
| The purpose of the script is to monitor the size of the three main logs
| on a Windows 2003 server and send and email should any of the logs get
| shorter. It works fine... just don't know *why* it produces the '[Errno
| 9] Bad File Descriptor' error.
|
| I'm running Python 2.4.1 on Windows 2003 SP1 Server with no funky win32
| extensions ;)
|
| logs = ['AppEvent.Evt', 'SecEvent.Evt', 'SysEvent.Evt']
|
| app_size = 0
| sec_size = 0
| sys_size = 0
|
| def send_email(LogName, old_size, new_size):
| f = "Somebody<XX*******@vt.edu>"
| t = "So***********@vt.edu"
|
| msg = MIMEText("""old_size = %d, new_size = %d""" %(old_size,
| new_size))
|
| msg["Subject"] = "%s Log Just Got Shorter" %LogName
| msg["Message-id"] = email.Utils.make_msgid()
| msg["From"] = f
| msg["To"] = t
|
| h = "smtp.vt.edu"
| s = smtplib.SMTP(h)
| s.sendmail(f, t, msg.as_string())
| s.quit()
|
| while 1:
|
| for log in logs:
|
| try:
|
| a = os.stat('C:\WINDOWS\System32\config\%s' %log)
Without looking at the rest of script:
Try using either escaped backslashes as in:
a = os.stat('C:\\WINDOWS\\System32\\config\\%s' %log)
or a raw string (as long as it doesn't end with a single backslash) as in:
a = os.stat(r'C:\WINDOWS\System32\config\%s' %log)
or simply use forward slashes as in:
a = os.stat('C:/WINDOWS/System32/config/%s' %log)
--
Vincent Wehren
| cur_size = a[6]
| print log
| print "cur_size", cur_size
|
| if log == 'AppEvent.Evt':
| print "old_size", app_size, "\n"
| if cur_size >= app_size:
| app_size = cur_size
| time.sleep(6)
| continue
| else:
| send_email(log, app_size, cur_size)
| time.sleep(6)
| continue
|
| elif log == 'SecEvent.Evt':
| print "old_size", sec_size, "\n"
| if cur_size >= sec_size:
| sec_size = cur_size
| time.sleep(6)
| continue
| else:
| send_email(log, sec_size, cur_size)
| time.sleep(6)
| continue
|
| else:
| print "old_size", sys_size, "\n"
| if cur_size >= sys_size:
| sys_size = cur_size
| time.sleep(6)
| continue
| else:
| send_email(log, sys_size, cur_size)
| time.sleep(6)
| continue
|
| except Exception, e:
| fp7 = file('log_mon_exception.txt', 'a')
| print >> fp7, e
| fp7.close() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kevin |
last post by:
Has anyone else run into random IOErrors ( bad file descriptor) in
multi-threaded Python apps?
I've searched the newsgroups, and the only references I can find to that
seem to be sporadically...
|
by: Morten Gulbrandsen |
last post by:
mysql> USE company;
Database changed
mysql>
mysql> DROP TABLE IF EXISTS EMPLOYEE;
--------------
DROP TABLE IF EXISTS EMPLOYEE
--------------
Query OK, 0 rows affected (0.00 sec)
|
by: Jeevan |
last post by:
Hi,
I have some data which I am getting from a socket. I am currently
storing the
data in an array (so that future reading of the data will be fast as
it will
be in RAM instead of hard disk)....
|
by: jacob navia |
last post by:
Recently there was a discussion in this group about
how to retrieve the file name given a FILE *.
The question raised my curiosity, and after some
research I have come up with a good...
|
by: Ben Dewey |
last post by:
Project:
----------------------------
I am creating a HTTPS File Transfer App using ASP.NET and C#. I am
utilizing ActiveDirectory and windows security to manage the
permissions. Why reinvent...
|
by: John Regan |
last post by:
Hello All
I am trying to find the owner of a file or folder on our network (Windows
2000 Server) using VB.Net and/or API. so I can search for Folders that don't
follow our company's specified...
|
by: Michael McGarry |
last post by:
Hi,
How do I interpret errno from fopen()? errno = 24 in my case.
Thanks for any help,
Michael
|
by: news |
last post by:
Recently our mail from our e-commerce site has been rejected by AOL due
to an IP block because someone was using our PHP scripts to send spam.
Well, I got that fixed.
But our legitimate...
|
by: Mark Gold |
last post by:
Hi! We have a VB application using Crystal Reports 6 that has worked
successfully on hundreds of systems for over 10 years. Now, on one
network, the application and access database does not close....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |