Hi,
Currently I am working on a script to automate the process of converting the log file from binary into text format. To achieve this, partly I am depending on my application�s utility for this conversion and the rest I am relying on shell commands to search for directory, locate the file and search for specific data in the converted file and email that to the user.
Here is the script that will do the work.
#!/bin/ksh
. /home/.env
# Go to the location where log file is stored.
cd $lOg_Path
cd `find . -type d |sort | tail -1`
LogName=`ls -ltr | grep -v 'resend' | grep -E '\.dat$'|tail -1 | awk '{ print $9 }'`
NewLogName=`echo $LogName | cut -f1 -d .`.txt
infacmd.sh isp ConvertLogFile -in $LogName -lo $NewLogName
tail -4 ${Log_File} > tmp.txt
#echo "=============================================================================================================================">>tmp.txt
#echo "Please find attached Log below">>tmp.txt
EndTime=`date +%H-%M-%S`
#( cat tmp.txt; uuencode $NewLogName $NewLogName) | mailx -s "Subject" `echo ${Alertlist_All}`
But the problem is that the converted output file wrapped for every 80 characters and rest of the information is printed on the next line. Due to this, I am having difficulty in searching for a specific data in the log file based on a date range along with timestamp and print the output.
Here is the file output
2011-09-26 INF UM_10 UserMana Starting synchronization for security domain
14:37:31 080 gementSe [12345].
rvice
2011-09-26 INF LDAP_ UserMana LDAP user [xxxx] in security domain
14:37:31 10002 gementSe [12345] queried with LDAP DN
rvice [CN=sreich,CN=Users,DC=DOMAIN,DC=COM].
2011-09-26 INF LDAP_ UserMana LDAP user [yyyyy] in security domain
14:37:31 10002 gementSe [12345] queried with LDAP DN
rvice [CN=yyyyy,CN=Users,DC=DOMAIN,DC=COM].
2011-09-26 INF LDAP_ UserMana LDAP user [zzzzz] in security domain [12345]
14:37:31 10002 gementSe queried with LDAP DN
rvice [CN=zzzzz,CN=Users,DC=DOMAIN,DC=COM].
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_LDAP] in
14:37:31 10003 gementSe security domain [12345] queried from LDAP.
rvice
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_LDAP] in
14:37:31 10004 gementSe security domain [12345] queried from LDAP
rvice contains user [yyyyy] in security domain
[12345].
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_LDAP] in
14:37:31 10004 gementSe security domain [12345] queried from LDAP
rvice contains user [zzzzz] in security domain
[12345].
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_LDAP] in
14:37:31 10004 gementSe security domain [12345] queried from LDAP
rvice contains user [sreich] in security domain
[12345].
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_ADM_LDAP] in
14:37:31 10003 gementSe security domain [12345] queried from LDAP.
rvice
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_ADM_LDAP] in
14:37:31 10004 gementSe security domain [12345] queried from LDAP
rvice contains user [yyyyy] in security domain
[12345].
2011-09-26 INF LDAP_ UserMana LDAP group [INFA_ADM_LDAP] in
14:37:31 10004 gementSe security domain [12345] queried from LDAP
rvice contains user [zzzzz] in security domain
[12345].
2011-09-26 INF LDAP_ UserMana Queried [3] users based on the user search base
14:37:31 10000 gementSe [CN=Users,DC=DOMAIN,DC=COM] with filter
rvice [(&(ObjectClass=user)(|(memberOf=CN=INFA_LDAP_ADM,\
CN=Users,DC=DOMAIN,DC=COM)(m
emberOf=CN=INFA_LDAP,CN=U
sers,DC=DOMAIN,DC=COM)))] specified in
[12345] security domain definition.
2011-09-26 INF LDAP_ UserMana Queried [2] groups based on the group search base
14:37:31 10001 gementSe [CN=Users,DC=DOMAIN,DC=COM] with filter
rvice [(&(ObjectClass=group)(|(CN=INFA_
LDAP_ADM)(CN=INFA_LDAP_DEV)))]
specified in [12345] security domain
definition.
2011-09-26 INF LDAP_ UserMana Security domain [12345] synchronization with
14:37:32 10007 gementSe LDAP server successful.
To overcome this problem, I am finding the row numbers of starting row and ending row which I am interested in and pass them back to the script and store them in variables. After that, I am printing the data to a output file based on the row numbers.
Here is the code I am thinking of putting into the code.
RowNum=`grep -n '$StartTime' 1_0.txt |head -1|cut -c 1`
cat 1_0.txt|awk 'NR>$RowNum'
I feel this is a crude way of coding but I am not aware of any better technique to handle this problem.
Sri