Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Relatively simple question regarding find and cmin Post 302382720 by DeCoTwc on Thursday 24th of December 2009 02:58:58 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
SCANLOGS(8)						    InterNetNews Documentation						       SCANLOGS(8)

NAME
scanlogs - Summarize and rotate INN log files SYNOPSIS
scanlogs [norotate] DESCRIPTION
scanlogs summarizes the information recorded in the INN log files which reside in the pathlog directory set in inn.conf (see newslog(5) for further details about these log files). It is normally invoked by the news.daily(8) script which performs daily server maintenance tasks. It invokes "ctlinnd flushlogs" to close the news and error log files, rename them to add ".old" to the file names and open fresh news and error logs; the active file is also flushed to disk, along with the history database. By default, scanlogs rotates and cleans out the logs. It keeps up to logcycles old compressed log files in pathlog/OLD (the logcycles parameter can be set in inn.conf). scanlogs also keeps archives of the active file in this directory. It invokes tally.control if newgroup.log or rmgroup.log exists in pathlog (see the control.log entry of newslog(5) for more information about that). scanlogs displays the contents of errlog and news.crit, if non-empty, and runs innreport to summarize the contents of news and news.notice, and to update the unwanted.log file amongst other things (see more information about that in innreport(8)). OPTIONS
Only one option is currently accepted: norotate Using this option disables the rotating and cleaning aspect of the log processing: the logs files are only scanned for information and no contents are altered. If scanlogs is invoked more than once a day, the norotate option should be used to prevent premature log cleaning. FILES
See newslog(5) for the list of log files processed by scanlogs. HISTORY
Written by Landon Curt Noll <chongo@toad.com> and Rich $alz <rsalz@uunet.uu.net> for InterNetNews. Converted to POD by Julien Elie. $Id: scanlogs.pod 8357 2009-02-27 17:56:00Z iulius $ SEE ALSO
inn.conf(5), innreport(8), news.daily(8), newslog(5), shlock(1), tally.control(8). INN 2.5.2 2009-05-21 SCANLOGS(8)
All times are GMT -4. The time now is 03:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy