Script to counting a specific word in a logfile on each day of this month, last month etc


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to counting a specific word in a logfile on each day of this month, last month etc
# 1  
Old 08-17-2011
Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All,
I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer.

Any ideas would be appreciated!
# 2  
Old 08-17-2011
What have you done so far?
# 3  
Old 08-17-2011
Code:
#!/bin/ksh
file="/tmp/filename"
MAILCMD="mail -s"
EMAILGR="emailaddress"
echo "The total count for the month of Aug 2011 is  --->"
cut -d' ' -f1,2,3,4,5,6,7,8,9 $file | grep -i "Aug" | grep -i "search keyword" | wc -l

I was able to output the keyword for the whole month using the above command. My approach was:
a. I split the log file to view only certain columns using cut command
b. I did a grep for the month and also a grep for the keyword for the count and finally wc -l to count the number of occurence!

Now, I am planning to use this same command for all the months!

I think we can make use of some kind of loop or whatever to make this more simpler and easier but unfortunately I do not have that kind of programming skill to come up with this kind of script in a short time!

At this point this script satisfies my current requirement. Any additional suggestions will be helpful to refine this script further!

Last edited by vbe; 08-18-2011 at 05:08 AM.. Reason: use code tags please
# 4  
Old 08-17-2011
Quote:
I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before.
What is the name format of your files?
# 5  
Old 08-17-2011
The file is applogfile.txt
Here is the format inside this file:
Mon Aug 15 17:00:11 EDT 2011 FTPChild ADD acctname acctsite test@test.com /nasftp05/testacct/TESTFTP/testsite.add=testftpsite|testmasteracct|testftpsite|wyh0104|test user
# 6  
Old 08-17-2011
if all you need IS a for loop for other months and your Aug logic works then:

Code:
for month in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
  do
echo "The total count for the month of $month 2011 is  --->"
cut -d' ' -f1,2,3,4,5,6,7,8,9 $file | grep -i "$month" | grep -i "search keyword" | wc -l
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to run on 2 4 and 7 day of the month

I am looking for a unix script which could run a job on 2, 4 and 7 working day of the month. if the days are falling on the saturday/sunday. it should run on the next day. Thank you.. (9 Replies)
Discussion started by: tradingspecial
9 Replies

2. Shell Programming and Scripting

Writing a script to run weekly/monthly - check for weekday or day-of-the-month

Hi all, I currently have a UNIX file maintenance script that runs daily as a cron job. Now I want to change the script and create functions/sub inside it that runs on a weekly or monthly basis. To run all the scripts' daily maintenance, I want to schedule it in cron as simply maint.sh... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. UNIX for Dummies Questions & Answers

Running Script via Crontab on 2nd Working day each month

Hello Guys, I have a questions regarding running a shell script every second working day each month. I have no clue how solve this problem :wall:. Important is that it has to be the second working (Mo-Fr). Example: If 1st and 2nd Days of month are Sat and Sun the script must run on 4th day... (5 Replies)
Discussion started by: Hollo
5 Replies

4. Shell Programming and Scripting

Need help in running script on last day of month

Hello Experts/Guru, I need a help in running the script on every month last day.... PS: due to some constrain I can't schedule in crontab Requirement: On Jan 31st i want to run some script, similarly on Feb 28th, March 31st, April 30th......till Dec 31st. Please help me by providing... (3 Replies)
Discussion started by: aks_1902
3 Replies

5. Shell Programming and Scripting

run the script for last day of the month

Hello Experts, I have a script which i want to run the on last day of every month. let say I have backup.sh script which i want to run it every month last day. Can anyone please help :confused: thanks (4 Replies)
Discussion started by: aks_1902
4 Replies

6. Shell Programming and Scripting

Code creates day 32 instead of 1st day of next month.

I am using the code below modified from a post I saw here regarding having the script write out future dates. The problem is that instead of making 8/1 it makes 7/32! Please help! yy=`date +%Y` mm=`date +%m` dd=`date +%d` echo "Today is : $yy $mm $dd" #!/usr/bin/ksh date '+%m... (5 Replies)
Discussion started by: libertyforall
5 Replies

7. Shell Programming and Scripting

Script to find previous month last day minus one day timestamp

Hi All, I need to find the previous month last day minus one day, using shell script. Can you guys help me to do this. My Requirment is as below: Input for me will be 2000909(YYYYMM) I need the previous months last day minus 1 day timestamp. That is i need 2000908 months last day minus ... (3 Replies)
Discussion started by: girish.raos
3 Replies

8. UNIX for Dummies Questions & Answers

cron script -run every 2nd day of month except Monday

I know I can't schedule this in cron and would have to write a wrapper around my script and schedule it in cron ....but not sure how do to this? How do I exclude Monday if the 2nd day of the month falls on a Monday? Thanks. I tried this: 0 0 2 * 0,2-6 command And I know this doesnt... (2 Replies)
Discussion started by: newtou
2 Replies

9. Shell Programming and Scripting

last month's logfile

hi friends I need a shell script which will do the following Task Enter the month : if you enter 1 then it ll show you last 1 month's (starting from today).log file in the current directry. if you enter 4 then it ll show you last 4 month's (starting from today).log file in the current... (2 Replies)
Discussion started by: deep_kol
2 Replies

10. Shell Programming and Scripting

Write a shell script to find whether the first day of the month is a working day

Hi , I am relatively new to unix... Can u pls help me out to find out if the first day of the month is a working day ie from (Monday to Friday)...using Date and If clause in Korn shell.. This is very urgent. Thanks for ur help... (7 Replies)
Discussion started by: phani
7 Replies
Login or Register to Ask a Question