help on log

Erik Price erikprice at mac.com
Wed Sep 4 10:35:40 EDT 2002


This message has popped up quite a few times on c.l.p. and on the Tutor 
list, under two different email addresses even.

If you are really new to any kind of programming, I think this script 
is a little bit advanced.  For instance, I see that you're using the 
regular expression module, but I'm not sure that you understand how to 
use it.  It looks like you're trying to compile a regular expression 
for the text that you want generated by the script, but regular 
expressions help you search for text in an already-existing file.  
Also, you're using the string module to find a "LayerUp" string, but I 
don't see that string anywhere in your log -- so is this really even 
necessary?  (Even if it's necessary to your code, it could be omitted 
from your post.)

Also, few people have the time to sit down and troubleshoot an entire 
script, even a small one like this.  If you knew exactly what your 
problem was, you could isolate the problem from the rest of the script 
and then just ask that question.  Once it's solved, you can move on to 
the next problem.  This mailing list gets so much traffic that I end up 
deleting a lot of the messages without reading them, even the short 
ones.  Long ones which vaguely ask for help and then post a lot of code 
go right to my Trash folder.

My advice to you is that you -not- tackle an entire script like this 
right off the bat.  Fire up your interactive Python interpreter.  
Import the regular expression and string modules.  Open up a file 
handle to your ppp.log file.  Then start playing with the various 
features of the regular expression and string modules, and see what you 
can do interactively.  When you can get something to look good, write 
down what you did.  When you have a straightforward question, go ahead 
and ask it here or on the Tutor list.

I'm not trying to sound mean, but you will find this a lot easier if 
you break it down into smaller steps.  The interactive Python 
interpreter is the ultimate tool for doing this.



Erik

PS: don't use HTML-formatted or Rich Text-formatted email, on some mail 
clients (such as mine) it makes your text render too small to read.  
That only exacerbates your problem.




On Wednesday, September 4, 2002, at 03:42  AM, Morne wrote:

> Could someone please help me with this? Im really new to any kind of 
> programming .If posible would you be
>  able to answer in detail.
>  
> Thanx
>  
>  HERE IS WHAT I HAVE:
>
>  import re
>  import string
>
>  secondsMatcher=re.compile("Connect time: (\d+) secs")
>
>  def getStuff(file):
>      closeline = 0
>      errorcount = 0
>      secondscount = 0
>      connectcount = 0
>      data_outcount = 0
>      data_incount = 0
>      ppplist = file.readlines()
>
>      for line in ppplist:
>
>        if string.find(line,"LayerUp") >= 0:
>            print "found connect"
>            connectline = string.split(line)
>            connectcount = connectcount + 1
>
>        elif string.find(line,"ERROR") >= 0:
>            print "found error"
>            errorcount = errorcount + 1
>
>         elif string.find(line,"Connect time") >= 0:
>            print "found close"
> connectSecs=secondsMatcher.search(line).group(1)
>            print "Connected for",connectSecs
>           closeline = string.split(line)
>            secondscount = secondscount + string.atoi(connectSecs)
>
>  def main():
>     f=open("C:/my documents/ppp.log","r")
>      getStuff(f)
>      return None
>
>  if __name__=="__main__":
>      main()
>
>  THIS IS WHAT I NEED THE PROGRAM TO DO:
>
>  I want the program to read the attached ppp.log file and give me the
>  following type of report:
>
>
>  PPP Log file summary for 5 Jul 2002
>  -----------------------------------
>  Jul  5 18:15:01 Connected to internet (IP 155.239.150.146)
>  Jul  5 18:18:08 Closed connection. ( Connect time: 197 secs: 5091 
> octets
> in,
>  1864 octets out )
>  -----------------------------------
>  Successful connections: 5
>  Failed connections: 2
>  Total time online: 456 seconds Total data in: 66576 octets
>  Total Data out: 66349 octets
>
> HERE IS part of the olg file seems noone wants to touch the 
> Attachment(lol)
>
> > Jul  5 18:00:00 maxigate newsyslog[87300]: logfile turned over
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local 
> client.
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: 
> quit
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: 
> Client
> connection dropped.
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: Connected to local 
> client.
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: 
> set
> timeout 180
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Command: /var/run/internet: 
> dial
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: bundle: Establish
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: closed -> 
> opening
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: Connected!
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: deflink: opening -> 
> dial
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Chat: Phone: 0860007249
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Chat: deflink: Dial attempt 
> 1 of
> 1
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Phase: /var/run/internet: 
> Client
> connection closed.
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Chat: Send: AT^M
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Chat: Expect(5): OK
> Jul  5 18:15:00 maxigate ppp[34607]: tun0: Chat: Received: AT^M^M
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: ATE1Q0^M
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Expect(5): OK
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: ATE1Q0^M^M
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Received: OK^M
> Jul  5 18:15:01 maxigate ppp[34607]: tun0: Chat: Send: 
> ATx1DT0860007249^M
> Jul  5 18:15:03 maxigate ppp[34607]: tun0: Chat: Expect(40): CONNECT
> Jul  5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received:
> ATx1DT0860007249^M^M
> Jul  5 18:15:22 maxigate ppp[34607]: tun0: Chat: Received: CONNECT
> 33600/ARQ/V34/LAPM/V42BIS^M
> Jul  5 18:15:22 maxigate ppp[34607]: tun0: Phase: deflink: dial -> 
> carrier
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: /dev/cuaa0: 
> CD
> detected
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: carrier -> 
> login
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: Phase: deflink: login -> lcp
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: LCP: FSM: Using "deflink" 
> as a
> transport
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change
> Initial --> Closed
> Jul  5 18:15:23 maxigate ppp[34607]: tun0: LCP: deflink: State change
> Closed --> Stopped
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: LayerStart
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP: deflink: 
> SendConfigReq(179)
> state = Stopped
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP:  ACFCOMP[2]
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP:  PROTOCOMP[2]
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP:  ACCMAP[6] 0x00000000
> Jul  5 18:15:24 maxigate ppp[34607]: tun0: LCP:  MRU[4] 1500
> Jul  5 18:15:2
>
>
>





--
Erik Price

email: erikprice at mac.com
jabber: erikprice at jabber.org





More information about the Python-list mailing list