473,671 Members | 2,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[Errno 9] Bad File Descriptor on Windows 2003 Server & Py 2.4.1

rbt
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(LogN ame, 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.mak e_msgid()
msg["From"] = f
msg["To"] = t

h = "smtp.vt.ed u"
s = smtplib.SMTP(h)
s.sendmail(f, t, msg.as_string() )
s.quit()

while 1:

for log in logs:

try:

a = os.stat('C:\WIN DOWS\System32\c onfig\%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_e xception.txt', 'a')
print >> fp7, e
fp7.close()
Jul 19 '05 #1
1 2791
"rbt" <rb*@athop1.ath .vt.edu> schrieb im Newsbeitrag
news:d5******** **@solaris.cc.v t.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(LogN ame, 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.mak e_msgid()
| msg["From"] = f
| msg["To"] = t
|
| h = "smtp.vt.ed u"
| s = smtplib.SMTP(h)
| s.sendmail(f, t, msg.as_string() )
| s.quit()
|
| while 1:
|
| for log in logs:
|
| try:
|
| a = os.stat('C:\WIN DOWS\System32\c onfig\%s' %log)

Without looking at the rest of script:

Try using either escaped backslashes as in:

a = os.stat('C:\\WI NDOWS\\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:\WI NDOWS\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_e xception.txt', 'a')
| print >> fp7, e
| fp7.close()
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
16216
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 related to threading, but nobody seems to have a "fix" or even a clear understanding of what the issue is. The app I'm running into this with (once in a while... not really repeatable predictably) is using 3 threads, and I'm using locks around all...
0
3035
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)
11
3331
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). Is there any way I can treat this array as a file i.e. can I apply file operations (like fopen, fscanf etc) on this array without having to write the data into a physical file and then read
33
2350
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 implementation. The solution is in the tutorial for lcc-win32 (http://www.cs.virginia.edu/~lcc-win32) page 331.
9
10889
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 the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
2
5038
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 folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
6
20195
by: Michael McGarry | last post by:
Hi, How do I interpret errno from fopen()? errno = 24 in my case. Thanks for any help, Michael
7
6859
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 auto-generated e-mails are getting "deferred" by AOL now with an error: Deferred: Bad file descriptor I can't find anything on their support site about this, nor Googling. Any ideas?
0
2332
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. It seems to hang on the command. When we open the application an peruse the screens without opening up a report (using crystal reports), the application and access db closes fine. But as soon as we run a report and then close the report and...
0
8911
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.