Relatively simple question regarding find and cmin


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Relatively simple question regarding find and cmin
# 1  
Old 12-24-2009
Relatively simple question regarding find and cmin

Nuts and bolts:

I have a log file that should be updated once every minute called OD_MEM.log. I want to add a check to my CheckSystem script that confirms that the log has been written to in the last 2 minutes. If I use the find command with cmin 1, it finds the file every time. If I use the find command with cmin 2 it does not find the file. Is the cmin option looking for files modified exactly n minute ago, or within the last n minute. Meaning if I use cmin 2, shouldn't it find files modified within the last 2 minutes, which would include the file I'm looking for (since it was modified 1 minute ago).

Code:
[root@mys-nycsm-srv01 logs]# date && ls -ltr /usr/local/mystro/logs/OD_MEM.log&&find /usr/local/mystro/logs/OD_MEM.log -cmin  1
Thu Dec 24 14:49:10 EST 2009
-rw-rw----  1 mystro mystro 11102934 Dec 24 14:48 /usr/local/mystro/logs/OD_MEM.log
/usr/local/mystro/logs/OD_MEM.log
[root@mys-nycsm-srv01 logs]# date && ls -ltr /usr/local/mystro/logs/OD_MEM.log&&find /usr/local/mystro/logs/OD_MEM.log -cmin  2
Thu Dec 24 14:50:07 EST 2009
-rw-rw----  1 mystro mystro 11103957 Dec 24 14:49 /usr/local/mystro/logs/OD_MEM.log
[root@mys-nycsm-srv01 logs]#

Now, just in case you'd like to laugh at how hard I worked on this before I realized I could just use find to check the modified time...

My original plan was to calculate how many lines there should be in the log based on the premise that for every hour there would be 60 lines and then in the latest hour add the number of minutes and compare it against the actual number of lines. It actually works, but I realize now it's an incredibly convoluted solution, so I'm hoping to better understand the find command and replace it.

Code:
OD_MEM_LINES=$(grep -c `date '+%Y-%m-%d'` /usr/local/mystro/logs/OD_MEM.log)
OD_HOUR=$(tail -2 /usr/local/mystro/logs/OD_MEM.log|awk '/2009/{print $2}'|cut -f1 -d:)
    if [[ $OD_HOUR -eq 00 ]];then
        OD_LINES_CAL=`tail -2 /usr/local/mystro/logs/OD_MEM.log|awk '/2009/{print $2}'|cut -f2 -d:`
    else
        OD_LINES_CAL=$(( ($OD_HOUR * 60 ) + `tail -2 /usr/local/mystro/logs/OD_MEM.log|awk '/2009/{print $2}'|cut -f2 -d:` ))
    fi
    if [[ $OD_MEM_LINES -lt $OD_LINES_CAL ]];then 
        printf "+-++-++-++-++-++-++-++-++-++-++-++-++-++-+\n"
        printf "There may be a problem with the On Demand Memory Manager.\n"
        printf "Was expecting there to be $OD_LINES_CAL lines in the OD_MEM.log, but only found $OD_MEM_LINES\n"
        printf "If there is a major difference between these two numbers, check the OD_MEM.log that a line has scrolled in the last 2 minutes\n" 
        printf "+-++-++-++-++-++-++-++-++-++-++-++-++-++-+\n"
    fi

# 2  
Old 12-25-2009
I believe you need:

Code:
-cmin -2

From man find:

Quote:
TESTS

[...]

Numeric arguments can be specified as

+n for greater than n,

-n for less than n,

n for exactly n.
# 3  
Old 12-26-2009
Well crap...

Thanks man. The only thing worse than the amount of effort I put into that is how simple the solution was.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Any alternative for mmin or cmin parameter

Hi, I need to write a shell script where I need to check whether log file is generated in last 1 hour or not. But I am getting below error in using mmin or cmin parameter with find command: find: bad option -mmin find: bad option -cmin So my concern is that any alternative for mmin option... (5 Replies)
Discussion started by: Ankit Srivastav
5 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. Shell Programming and Scripting

Find mmin, mtime, cmin not working

Dear All, We are having the script which is creating the folder on another server if it is not present using ssh. Using scp it copies copy all pdf files from local folder to server folder. After all copy is done, Just to verify i was using the below find command find... (3 Replies)
Discussion started by: yadavricky
3 Replies

4. Shell Programming and Scripting

Simple if then else question

I am having trouble making this statement work. I am passing in a number value for the number of days to keep archive logs for and wanted to make sure that it is a number. I have a script that will return 1 for is a number and 0 for is not a number. I also want to make sure that the number is not... (2 Replies)
Discussion started by: gandolf989
2 Replies

5. Solaris

AIX to SOLARIS conversion - (find -cmin option)

I have a piece of code (below) in a .ksh script running on AIX. I need to convert the code to run .zsh on Solaris. Solaris's find command does not support the -cmin function. Suggestions?? The code searchs for a file (_filename) and determines if it has been written to or modified in the last... (1 Reply)
Discussion started by: nmalencia
1 Replies

6. UNIX for Dummies Questions & Answers

Simple question

I had a script in solaris wich i read data, for example: Number 1: _ and the cursor use to be in '_' place because in the code of the script i write: echo "Number 1:\c" but i copy the script to a linux and the cursor 'jump' to the begining of the next line like: Number 1:... (2 Replies)
Discussion started by: lestat_ecuador
2 Replies

7. UNIX for Advanced & Expert Users

find -cmin or fin -newer

I am running SUSE/8 and SUSE/9 on a high end server (4 CPU, 8G RAM etc) I have a huge directory structure with over 4million files in it. I have find the files that are modified (created, modified, renamed etc etc) in the last 10 minutes periodically. I have tried "find -cmin -10" and "find... (2 Replies)
Discussion started by: xxxyyyy
2 Replies

8. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

9. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

10. UNIX for Dummies Questions & Answers

Simple question

I am taking an intro to unix class and I can not figure out how to do part of the question. I am writing script to be exictued by a program in the tutoral. Question: Write every line containing the word ``delete'' produced by ``man mail'' into a file called ``delete''. Hint: What does using... (1 Reply)
Discussion started by: weathergirl
1 Replies
Login or Register to Ask a Question