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
# 8  
Old 04-14-2009
Running Sun Solaris, kinda looking to use the standard options that come with BASH or KSH? Unfortuantely not that knowledgable on UNIX yet.
# 9  
Old 04-14-2009
which version? If you have version 10
Code:
use Time::Local;

my $fourtydays = 3456000; #3456000secs
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year+=1900;
$mon+=1;
my $now = timelocal(0,0,0,$mday,$mon,$year);
my $date= timelocal(0,0,0,3,3,2009);
while(<>){
 if (/Login succeeded/ ) {
    @list = split /:|\s/,$_;
    my $logdate= $list[3];    
    if( $logdate =~ /\// ){
        @d = split /\//,$logdate;
        my $date_one = timelocal(0,0,0,$d[2],$d[1],$d[0]);
        if ( ($now - $date_one ) >= $fourtydays ) { print $_; }
    }
 }
}

# 10  
Old 04-15-2009
Yeah, its Solaris 10.
Thanks alot for all your input. Will be finishing this off hopefully today sometime if time permits.
Once again, Much appreciated.
# 11  
Old 04-15-2009
Quote:
Originally Posted by ghostdog74
which version? If you have version 10
Code:
use Time::Local;

my $fourtydays = 3456000; #3456000secs
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year+=1900;
$mon+=1;
my $now = timelocal(0,0,0,$mday,$mon,$year);
my $date= timelocal(0,0,0,3,3,2009);
while(<>){
 if (/Login succeeded/ ) {
    @list = split /:|\s/,$_;
    my $logdate= $list[3];    
    if( $logdate =~ /\// ){
        @d = split /\//,$logdate;
        my $date_one = timelocal(0,0,0,$d[2],$d[1],$d[0]);
        if ( ($now - $date_one ) >= $fourtydays ) { print $_; }
    }
 }
}

Don't add one to the month, the timelocal() function expects the same month as localtime() returns, 0-11, not 1-12. Otherwise you throw off the calculation by a month. Or did I miss something?
# 12  
Old 04-15-2009
Quote:
Originally Posted by KevinADC
Don't add one to the month, the timelocal() function expects the same month as localtime() returns, 0-11, not 1-12. Otherwise you throw off the calculation by a month.
let's leave it to OP to test it out Smilie
# 13  
Old 04-15-2009
Quote:
Originally Posted by ghostdog74
let's leave it to OP to test it out Smilie
Cool, can I borrow the car Dad? Smilie
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