Finding all occurences in a file within the last 40 days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding all occurences in a file within the last 40 days
# 1  
Old 04-14-2009
Finding all occurences in a file within the last 40 days

Morning,

I have a database log file that i need to scan thru to find all successful logins within the last 40 days,
What i have currently done is create a bash script to scan the last month and pipe out the results to a text file.

Code:
YEAR=`date '+%Y'`
MONTH=`date '+%m'`
grep 'Login succeeded' $SYBASELOG > $TMP2
grep "$YEAR/$MONTH" $TMP2 > $TMP3

How would i be able to scan for the 'Login succeeded' pattern within the last 40 days?
Thanks

Last edited by Yogesh Sawant; 04-14-2009 at 06:03 AM.. Reason: added code tags
# 2  
Old 04-14-2009
show a sample of your log file
# 3  
Old 04-14-2009
Quote:
Originally Posted by ghostdog74
show a sample of your log file
Hi GhostDog,
I've removed the IP's, Usernames and have taken some random samples from the log.

02:00000:00187:2009/02/01 06:00:01.45 Logon Login succeeded. User:, Client IP address:
03:00000:00028:2009/02/12 06:00:02.41 Logon Login succeeded. User:, Client IP address:
03:00000:00103:2009/02/12 06:00:02.41 Logon Login succeeded. User: , Client IP address
00:00000:00143:2009/03/14 06:00:02.66 Logon Login succeeded. User:, Client IP address:
01:00000:00435:2009/03/18 06:00:03.80 Logon Login succeeded. User:, Client IP address:
00:00000:00368:2009/04/14 06:00:04.56 Logon Login succeeded. User:, Client IP address:
03:00000:00329:2009/04/14 06:04:08.07 Logon Login failed. User: Client IP address:
01:00000:00414:2009/04/14 06:49:48.87 Logon Login succeeded. User:, Client IP address
00:00083:00022:2009/04/14 06:49:51.66 server Deadlock Id 5742 detected
00083:00022:Deadlock Id 5742: detected. 1 deadlock chain(s) involved.
00083:00022:Deadlock Id 5742: Process (Familyid 44, Spid 94, Suid 3) was executing a SELECT command at line 10.

Last edited by Yogesh Sawant; 04-14-2009 at 06:04 AM.. Reason: disabled smilies
# 4  
Old 04-14-2009
if your platform supports Perl and Date:Calc module
Code:
use Date::Calc qw(:all);
my @date_time = Add_Delta_DHMS(Today_and_Now(),-40, 0, 0, 0 ); #last 40 day's date
my ($d_yr,$d_mth,$d_day) = ($date_time[0],$date_time[1],$date_time[2]);
$d_mth="0".$d_mth if length($d_mth)==1;
$d_day="0".$d_day if length($d_day)==1;
$d_date="$d_yr$d_mth$d_day";
while(<>){
 if (/Login succeeded/ ) {
    @list = split /:|\s/,$_;
    my $logdate= $list[3];    
    if( $logdate =~ /\// ){
        @d = split /\//,$logdate;
        my $date_one = "$d[0]$d[1]$d[2]";
        if ( $date_one  >= $d_date) { print $_."\n"; }
    }
 }
}

# 5  
Old 04-14-2009
Quote:
Originally Posted by ghostdog74
if your platform supports Perl and Date:Calc module
And if the server does not have the Date module installed, Time::Local and a little bit more code can be used to figure out the interval between the dates.
# 6  
Old 04-14-2009
Thanks guys,
Much appreciate the assistance.
Is there however a simpler way of doing this without the perl scripting?
something like a mtime -40?
# 7  
Old 04-14-2009
Quote:
Originally Posted by Jefferson333
Thanks guys,
Much appreciate the assistance.
Is there however a simpler way of doing this without the perl scripting?
something like a mtime -40?
what platform are you in, and what tools do you have.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Finding files older than x days within directory with spaces

Hi, I am trying to run a command that finds all files over x amount of days, issue is one of the directories has spaces within it. find /files/target directory/*/* -type f -mtime +60 When running the above the usual error message is thrown back + find '/files/target\' 'directory/*/*' -type... (1 Reply)
Discussion started by: Ads89
1 Replies

2. UNIX for Dummies Questions & Answers

Finding days in previous month

#!/bin/ksh day=1 month=1 year=2012 if then then prevmonth=31 elif then prevmonth=30 elif then then prevmonth=29 elif then prevmonth=29 else prevmonth=28 fi (4 Replies)
Discussion started by: vagar11
4 Replies

3. UNIX for Dummies Questions & Answers

Number of word occurences in a file?

Hello world, Can anybody tell me how to count how many times does a word repeat in a file? There have been many threads on this but they all are heavy loads of Scripting for a starter like me. :D So, I sat down today and after some hours of reading man pages, I found a simple one-line... (18 Replies)
Discussion started by: satish51392111
18 Replies

4. UNIX for Advanced & Expert Users

Finding user accounts not accessed for a specific number of days

Hi all, Recently I came across a challenge of finding the user accounts lying around on servers and not being used so much. Our client has hundreds of AIX, RedHat, and Solaris servers. For AIX, I have made a script which uses lsuser and a little bit of sed and awk to show the user accounts... (7 Replies)
Discussion started by: admin_xor
7 Replies

5. Shell Programming and Scripting

Finding occurences of numbers

I have two files The first file is in following format 5 937 8 1860 5 1 683 2 1 129 2 2 5 938 8 1122 5 1 20 520 4 1860 1851 1 5 939 8 1122 1124 1 20 521 4 5883 14 6 1860 1852 1 683 4 2 (5 Replies)
Discussion started by: stuggler
5 Replies

6. Shell Programming and Scripting

Finding directories older than 5 days

Hello, Motive: Search all directories which are older than 5 days. Example: consider following directory structure: abc/dir1 abc/dir1/dir abc/dir2 abc/dir3 abc/dir3/temp Suppose dir1 and dir3 are 5 days older. Then I am looking for a command which lists abc/dir1 and abic/dir3 only so that... (4 Replies)
Discussion started by: mytempid07
4 Replies

7. Shell Programming and Scripting

Script for parsing directories one level and finding directories older than n days

Hello all, Here's the deal...I have one directory with many subdirs and files. What I want to find out is who is keeping old files and directories...say files and dirs that they didn't use since a number of n days, only one level under the initial dir. Output to a file. A script for... (5 Replies)
Discussion started by: ejianu
5 Replies

8. Shell Programming and Scripting

Deleting / finding files older than X days missess a day

Hi When trying to find and delete files which are, say, 1 day, the find command misses a day. Please refer the following example. xxxd$ find . -type f -ctime +1 -exec ls -ltr {} \; total 64 -rw-rw-r-- 1 oracle xxxd 81 Apr 30 11:25 ./ful_cfg_tmp_20080429_7.dat -rw-rw-r-- 1... (4 Replies)
Discussion started by: guruparan18
4 Replies

9. Shell Programming and Scripting

Finding cumulative size of files older than certain days

Hi All, I've got a ton of files in a particular directory. I want to find pdf files older than 30 days in that directory and then the cumulative size of those files. Ex: find /home/jk/a -name "*.pdf" -mtime +30 consider it finds the below 4 files. /home/jk/a/1.pdf /home/jk/a/2.pdf... (1 Reply)
Discussion started by: rohan076
1 Replies

10. UNIX for Dummies Questions & Answers

Counting occurences of different strings in a file

Hi, i'd like to know if the following is possible with a shell script, and can't find the answer in the search. Suppose i have a logfile build like this: # 8 :riuyzp1028 # 38 : riuyzp1028 # 25 : riuyvzp1032 # 30 : nlkljpa0202 # 1 : nlklja0205 # 38 : riuyzp1028 # 25 :... (4 Replies)
Discussion started by: Freerider
4 Replies
Login or Register to Ask a Question