Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Looking code to convert my strings of line in Dict
#1
I want to read all the file in that location by today's date & result as output I want the uid list that BIND in ldap & cn list that search against netgroup.
but as all line is not remain same I am unable to get the way to write a code. please help me if you have better ID ...
this files have thousands of line.


this is my code:
import glob
import time
import re
from collections import defaultdict
date = time.strftime("%Y%m%d")
print date
list_of_files = glob.glob('/u01/app/oracle/product/ds/ora-nis-nl/txnlogs/access.' + date + '-*[1-9]')
#print list_of_files
    for file in list_of_files:
        with open(file, 'r') as list_of_files:
            z = list_of_files.readlines()
            #print line
            for line in z:
                key, value = line.strip().split(':')
                y[key].append(value)
                print (y)
        list_of_files.close()
-----------------------------------------
Result on execution
Error:
Traceback (most recent call last): File "pulllog1.py", line 14, in <module> key, value = line.strip().split() ValueError: too many values to unpack
-------------------------------------------sample of file content-------that code is reading line by line--
Output:
[10/Nov/2017:07:26:30 +0000] conn=8150491 op=3639285 msgId=3639286 - SRCH base="ou=people,dc=example,dc=com" scope=1 filter="(&(objectClass=posixAccount)(uidNumber=-2))" attrs="userPassword cn gidNumber uidNumber loginShell objectClass gecos uid homeDirectory" [10/Nov/2017:07:26:30 +0000] conn=8150491 op=3639285 msgId=3639286 - RESULT err=0 tag=101 nentries=0 etime=0 [10/Nov/2017:07:26:30 +0000] conn=8150492 op=3642946 msgId=3642947 - SRCH base="ou=people,dc=example,dc=com" scope=1 filter="(&(objectClass=posixAccount)(uidNumber=-2))" attrs="userPassword cn gidNumber uidNumber loginShell objectClass gecos uid homeDirectory" [10/Nov/2017:07:26:30 +0000] conn=8150492 op=3642946 msgId=3642947 - RESULT err=0 tag=101 nentries=0 etime=0 [10/Nov/2017:07:26:30 +0000] conn=8150491 op=3639286 msgId=3639287 - SRCH base="ou=people,dc=example,dc=com" scope=1 filter="(&(objectClass=posixAccount)(uidNumber=-2))" attrs="userPassword cn gidNumber uidNumber loginShell objectClass gecos uid homeDirectory" [10/Nov/2017:07:26:30 +0000] conn=8150491 op=3639286 msgId=3639287 - RESULT err=0 tag=101 nentries=0 etime=0 [10/Nov/2017:07:26:30 +0000] conn=8150492 op=3642947 msgId=3642948 - SRCH base="ou=people,dc=example,dc=com" scope=1 filter="(&(objectClass=posixAccount)(uidNumber=-2))" attrs="userPassword cn gidNumber uidNumber loginShell objectClass gecos uid homeDirectory" [10/Nov/2017:07:26:30 +0000] conn=8150492 op=3642947 msgId=3642948 - RESULT err=0 tag=101 nentries=0 etime=0 [10/Nov/2017:07:26:31 +0000] conn=8150491 op=3639287 msgId=3639288 - SRCH base="ou=people,dc=example,dc=com" scope=1 filter="(&(objectClass=posixAccount)(uidNumber=-2))" attrs="userPassword cn gidNumber uidNumber loginShell objectClass gecos uid homeDirectory" [10/Nov/2017:07:26:31 +0000] conn=8150491 op=3639287 msgId=3639288 - RESULT err=0 tag=101 nentries=0 etime=0 [10/Nov/2017:07:27:31 +0000] conn=2931239 op=2054033 msgId=2054034 - RESULT err=0 tag=101 nentries=1 etime=0 [10/Nov/2017:07:27:31 +0000] conn=2931239 op=2054034 msgId=2054035 - SRCH base="ou=netgroup,dc=example,dc=com" scope=1 filter="(&(objectClass=nisNetgroup)(cn=cloud_santosh_db))" attrs="cn nisNetgroupTriple memberNisNetgroup" [10/Nov/2017:07:27:31 +0000] conn=3139057 op=1041247 msgId=1041248 - SRCH base="ou=netgroup,dc=example,dc=com" scope=1 filter="(&(objectClass=nisNetgroup)(cn=cloud_ancg_prod_arch_db))" attrs="cn nisNetgroupTriple memberNisNetgroup" [10/Nov/2017:07:28:07 +0000] conn=8860723 op=2 msgId=3 - BIND dn="uid=sftoopemm,ou=people,dc=example,dc=com" method=128 version=3
buran wrote Nov-10-2017, 09:03 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
Maybe this helps:

#!/usr/bin/python3
import glob
import time

date = time.strftime("%Y%m%d")
filenames = glob.glob('./access.' + date + '-*[1-9]')

for filename in filenames:
    print(filename)
    with open(filename, 'r') as file:
        for line in file:
            line = line.strip()
            print(line)
            # do something with line
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Sort a dict in dict cherry_cherry 4 289 Apr-08-2020, 12:25 PM
Last Post: perfringo
  Convert dict from list - HELP! PLEASE! cherry_cherry 4 230 Apr-06-2020, 06:39 PM
Last Post: cherry_cherry
  Need explanation of one line of code Fliberty 6 333 Feb-18-2020, 12:50 AM
Last Post: Fliberty
  Translate this line of code please keystone76 2 291 Jan-31-2020, 11:15 PM
Last Post: keystone76
  Generate simple melodic line from code QuarterMissiv 7 436 Jan-09-2020, 05:27 PM
Last Post: QuarterMissiv
  Python convert multi line into single line formatted string karthidec 2 768 Dec-23-2019, 12:46 PM
Last Post: karthidec
  Phyton code to load a comma separated csv file in to a dict and then in to a dB mrsenorchuck 2 459 Nov-29-2019, 10:59 AM
Last Post: mrsenorchuck
  Error in the code ->ValueError: could not convert string to float: ' ' eagleboom 1 893 Nov-29-2019, 06:19 AM
Last Post: ThomasL
  convert strings of date to datetime exported from CSV GiorgosPap31 1 471 Oct-31-2019, 02:37 PM
Last Post: buran
  convert list of dict to dict of array of list with pop up kk230689 1 401 Sep-13-2019, 07:29 AM
Last Post: perfringo

Forum Jump:


Users browsing this thread: 1 Guest(s)