Thread: file log

Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I'm assuming by output that you mean the 'sever = lines' string that we discussed before but you can do this in one of three ways. Open a file in write or append (in this example this is called output) and replace the print like with.

    1) print >> output, '%2s = %10s' % (line.strip(), total)
    2) output.write('%2s = %10s' % (line.strip(), total))

    Or assuming you want to overwrite existing data you can use this form from the command line.

    3) python program.py > output.txt

    Is this what you wanted,

    Mark.
    programming language development: www.netytan.com Hula

  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    57
    Rep Power
    11
    still strugling any help

    Code:
    import os
    path='c:/serverfile.txt'
    eq= '='
    for line in file(path):
        os.chdir('//%s/mat/rulip' % line.strip())
        openlog = file('all.log').readlines()
        total=len(openlog)
        list=line.strip(),eq,total
        list=(line.upper().strip().rjust(13),str(total).rjust(4))
       flist=open("c:/serverfile3.txt").readlines()
       shutil.copy("list","flist")
  4. #18
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Still i cant see you importing shutil anywhere in your program, so im sure there will be an import error at some point. Also, it seems that you have two indentation levels within the for loop.

    list=line.strip(),eq,total
    list=(line.upper().strip().rjust(13),str(total).rjust(4))
    Ironic that 'list' is a tuple? you desided . Anyway, you are defining a variable and then redefining this on the next line, so, theres really no need for the first here.

    Could you write down the steps you want to take i.e. what the program has to do step by step and the input/output you want . Im kinda tired right now but tomorrow i will see what i can do about this problem for you.

    Night,

    Mark.
    programming language development: www.netytan.com Hula

  6. #19
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    57
    Rep Power
    11
    Sorry mark the first line you pointed out
    list=line.strip(),eq,total was a mistake

    Like i said before

    i want to collect the log files from my 6 servers(local servers) and keep the details of the server and the total line of each servers log file in to an other file something like this
    i.e c:\serverfile2.txt
  8. #20
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Code:
    #!/usr/bin/env python
    
    from shutil import copy
    
    output = 'output.txt'
    config = 'server.txt'
    server = '//%s/mat/rulip/all.log'
    
    for line in file(config):
        line = line.strip()
        count = len(file(server % line, 'r').readlines())
        file(output, 'w').write('%s has %10s lines.' % (line, count))
        copy(server % line, '%s_log.txt' % line)
    Ok, untested but this should work, in theory anyway. Obviously i dont have the same directories as you do so, not something i can test . Give it a go and see what happens.

    Mark.
    programming language development: www.netytan.com Hula

  10. #21
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    57
    Rep Power
    11
    Hi mark
    Thanks for your help
    But Still??????????????????????//

    Code:
    import os
    output=c:/serverfile1.txt
    path='c:/serverfile.txt'
    for line in file(path):
        os.chdir('//%s/mat/rulip' % line.strip())
        openlog = file('all.log').readlines()
        total=len(openlog)
        
    not working   output.write("%s = %s")%(line.strip(),total)
    This is want i want get the line(servers names) and total(total line of each log file) to an other file

    The previous two did not work
  12. #22
  13. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok, so you want to do the same thing as before only this time you don't want to copy the file to a local directory? Anyway, this line:

    output.write("%s = %s")%(line.strip(),total)
    Should actually look something like this:

    Code:
    file(output, 'a').write('%s = %s' % (line.strip(), total))
    since 'output' is the path to the file you want to store the data in. This file has to be opened in append mode or the file will only contain the values from the last time though the loop.

    Mark.
    programming language development: www.netytan.com Hula

  14. #23
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Heres a quick rewrite of your code which opens the output file prior to the loop and closes when this is done. As you probably knowticed, you can now use ouput.write().

    Code:
    #!/usr/bin/env python
    
    import os
    
    path = 'c:/serverfile.txt'
    
    output = file('c:/serverfile1.txt', 'w')
    for line in file(path):
        os.chdir('//%s/mat/rulip' % line.strip())
        openlog = file('all.log').readlines()
        total=len(openlog)
        output.write('%s = %s' % (line.strip(), total))
    output.close()
    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  16. #24
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    57
    Rep Power
    11
    Hi Mark
    I must confess 'YOU ARE A GENIUS'
    After all the help by you, I now got what i want

    Thanks a lo0000000000000000000000000000000000000t
  18. #25
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Not so much a genious or i would have got it right the first time and you wouldnt have had to spend all that time wondering wtf i was saying . In any case, just glad to help .

    Thanks mate,

    Mark.
    programming language development: www.netytan.com Hula

Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo