Grep by range of date from file creation in directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep by range of date from file creation in directory
# 1  
Old 09-21-2010
Grep by range of date from file creation in directory

Hi Expert,

Need your scripting and finding data so that it help me to find the culprit of this memory usage error.
Data provided here is a sample.

Process Snapshot directory: /var/spool/processes-snapshot

webdev9o9[93]% pwd
/var/spool/processes-snapshot

webdev9o9[97]% ls -lrct
-rw-r--r-- 1 root root 632 Sep 20 23:18 32590
-rw-r--r-- 1 root root 619 Sep 20 23:18 32586
-rw-r--r-- 1 root root 632 Sep 20 23:18 32577
-rw-r--r-- 1 root root 577 Sep 20 23:18 32573
-rw-r--r-- 1 root root 619 Sep 20 23:18 32562
-rw-r--r-- 1 root root 576 Sep 20 23:18 32559
-rw-r--r-- 1 root root 577 Sep 20 23:18 32549
-rw-r--r-- 1 root root 632 Sep 20 23:18 31010

What I want to achieve?
1. I would like to know base on /var/spool/processes-snapshot directory, where could I grep from certain time to certain time?

example from 20:00 t0 23:58 ?


2. And inside that file contain certain value that also could me, how could I grep by UID but showing by date of creation, then filter by range that I wanted?

e.g from certain time to certain time too?

sample output that I would like to have:
./24970:Uid: 10054 10054 10054 10054 Sep 20 23:18

webdev9o9 [98]% grep -r 10054 .
./24970:Uid: 10054 10054 10054 10054
./20861:Uid: 10054 10054 10054 10054
./30237:Uid: 10054 10054 10054 10054
./27920:Uid: 10054 10054 10054 10054
./15283:Uid: 10054 10054 10054 10054
./16827:Uid: 10054 10054 10054 10054
./7598:Uid: 10054 10054 10054 10054
./22903:Uid: 10054 10054 10054 10054
./20724:Uid: 10054 10054 10054 10054

webdev9o9[128]% cat 32590
Mon Sep 20 23:23:01 PDT 2010
Name: du
State: S (sleeping)
SleepAVG: 88%
Tgid: 32590
Pid: 32590
PPid: 32586
TracerPid: 0
Uid: 10054 10054 10054 10054
Gid: 1000 1000 1000 1000
FDSize: 64
Groups: 1000 5129 5130 8041
VmSize: 11648 kB
VmLck: 0 kB
VmRSS: 3296 kB
VmData: 1080 kB
VmStk: 2528 kB
VmExe: 317 kB
VmLib: 1479 kB
StaBrk: 00655000 kB
Brk: 006fa000 kB
StaStk: 7fbffffc90 kB
Threads: 1
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000002
SigIgn: 0000000000000000
SigCgt: 0000000000012000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000

Thank you.
Reggy
# 2  
Old 09-21-2010
Code:
cd /var/spool/processes-snapshot

ls -lrct |while read LINE
do

  awk -v min=2000 -v max=2359 '
     NR==1{split($4,a,":");h=a[1]a[2];y=$2 FS $3 FS a[1] ":" a[2]}
     /^Uid: /{if (h>=min&&h<=max) print FILENAME,$0,y}
     ' $LINE
done

# 3  
Old 09-21-2010
Hi rdcwayx,

Sorry for being so noob.

Could you please explain about above script? Thanks.
# 4  
Old 09-21-2010
Is the command fine?

the awk command take date from first line , take the uid from the Uid: line,then print with filename.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reason for no directory creation date

i read here that linux provides no way to determine when a directory was created. https://www.unix.com/shell-programming-and-scripting/157874-creation-date-directory.htmlI have a directory /home/andy/scripts that had a README file in it. That file says I put the script in that directory and... (3 Replies)
Discussion started by: drew77
3 Replies

2. Shell Programming and Scripting

Bash directory loop and order by creation date?

Hello, how in bash i can get directory loop and order by creation date? THX! :) #!/bin/bash for folder in /home/test/* do if ; then echo $folder; fi (12 Replies)
Discussion started by: ZerO13
12 Replies

3. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

4. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies

5. Emergency UNIX and Linux Support

How to move files from a directory which falls between Date Range?

Hi All, I am trying to to move files from a directory to another which falls from Current day - 7 days. The files are in zipped format with dates appended on it. Can you pls help me as this came as a immediate change before the production Release planned next week. Pls let me know if... (11 Replies)
Discussion started by: dsfreddie
11 Replies

6. UNIX Desktop Questions & Answers

grep a range of time & date

how can i grep a range? i have a text file with the following text: result.log.00:2012/01/02 12:00:07.422 LOG STARTED HERE N6Kashya29MemoryShieldScheduler_AO_IMPLE, pid=8662/8658, config=(alertThreshold=10,alertLevel=0,killThreshold=7200,coreThreshold=0,full=1), deltaTime=0,... (1 Reply)
Discussion started by: boaz733
1 Replies

7. Shell Programming and Scripting

Creation date of a directory

what's the command to find the creation date of a certain dirctory? (1 Reply)
Discussion started by: miss_dodi
1 Replies

8. Shell Programming and Scripting

grep - date & time range

Hi, I need to search email files by date & time range in email files. The timezone is not important. Can someone plz advise how i can do this ? For e.g A user can specify only A single date A date range date & time range Below is part of the email file. (4 Replies)
Discussion started by: coolatt
4 Replies

9. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

10. UNIX for Dummies Questions & Answers

Changing Creation Date to a Prespecified Date of a File In Unix

Dear Expert, Is there a command to do that in Unix? In such a way that we don't need to actually "write" or modified the content. -- monkfan (4 Replies)
Discussion started by: monkfan
4 Replies
Login or Register to Ask a Question