Logwatch python

Discussion in 'Python' started by Cleuson Alves, Feb 9, 2013.

  1. 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()
     
    Cleuson Alves, Feb 9, 2013
    #1
    1. Advertisements

  2. Cleuson Alves

    Roy Smith Guest

    In article <>,
    Cleuson Alves <> 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.
     
    Roy Smith, Feb 9, 2013
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cameron Laird
    Replies:
    3
    Views:
    872
    Dennis Lee Bieber
    Jun 28, 2003
  2. Irmen de Jong
    Replies:
    0
    Views:
    480
    Irmen de Jong
    Jun 30, 2003
  3. Gina Schuffenhauer

    Python 2.0 / Python 2.2

    Gina Schuffenhauer, Jul 1, 2003, in forum: Python
    Replies:
    0
    Views:
    403
    Gina Schuffenhauer
    Jul 1, 2003
  4. hab
    Replies:
    2
    Views:
    678
    Donn Cave
    Jul 7, 2003
  5. Irmen de Jong
    Replies:
    0
    Views:
    529
    Irmen de Jong
    Jul 7, 2003
  6. Replies:
    0
    Views:
    461
  7. JW
    Replies:
    1
    Views:
    761
    David Jeske
    Jul 12, 2003
  8. Replies:
    0
    Views:
    942
Loading...