Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Logwatch python

Reply
Thread Tools

Logwatch python

 
 
Cleuson Alves
Guest
Posts: n/a
 
      02-09-2013
Hello, I am trying to run this code, but I get an answer incorrect arguments numbers. someone could put an example of arguments for me to use in the / var / log?

Thank you.

################################################## ######################

import os, sys
from optparse import OptionParser

def main():
usage = "%prog [options] args"
parser = OptionParser(usage)
parser.add_option("-l", "--logfile", dest="logfile", help="Logfile to read data")
parser.add_option("-p", "--logpos", dest="logpos", help="File to store last log line read position")
parser.add_option("-f", "--find", dest="findstring", help="String to find in Logfile")
(options, args) = parser.parse_args()
if options.logfile is None or options.findstring is None or options.logpos is None:
print("Incorrect arguments numbers.\n")
parser.print_help()
sys.exit(-1)
else:
logfile = options.logfile
tofind = options.findstring
logpos = options.logpos

pos = 0
count = 0
if os.path.isfile(logpos):
pos = int(open(logpos).readline() or 0)
file = open(logfile)
file.seek(pos)
for line in file:
if line.find(tofind) != -1:
count += 1
pos = file.tell()
file.close()
file = open(logpos, 'w')
file.write(str(pos))
file.close()
print count

if __name__ == '__main__':

main()
 
Reply With Quote
 
 
 
 
Roy Smith
Guest
Posts: n/a
 
      02-09-2013
In article <(E-Mail Removed)>,
Cleuson Alves <(E-Mail Removed)> wrote:

> Hello, I am trying to run this code, but I get an answer incorrect arguments
> numbers. someone could put an example of arguments for me to use in the / var
> / log?


Since the first cave man tried to sort his rock collection into
descending order of mastodon kills, people have been inventing really
awesome debugging tools. One of the earliest, and still near the top of
most people's toolkits is the print statement.

You've got:

> if options.logfile is None or options.findstring is None or
> options.logpos is None:
> print("Incorrect arguments numbers.\n")


Start by printing out the values of options.logfile, options.findstring,
and options.logpos. Then at least you will know which of those three is
causing the problem.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 R. David Murray Python 0 01-17-2011 02:23 PM
Re: [Python-Dev] [python-committers] [RELEASED] Python 3.2 rc 1 Senthil Kumaran Python 0 01-17-2011 10:31 AM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Martin v. L÷wis Python 0 03-01-2008 10:51 PM
Re: [Python-Dev] [Python-3000] RELEASED Python 2.6a1 and 3.0a3 Paul Moore Python 0 03-01-2008 10:39 PM
Searching comp.lang.python/python-list@python.org (was: UTF-8) skip@pobox.com Python 0 03-10-2007 02:50 PM



Advertisments