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
SYSLOG2DLF.IN(1)					  LogReport's Lire Documentation					  SYSLOG2DLF.IN(1)

NAME
syslog2dlf - convert syslog log files to DLF SYNOPSIS
syslog2dlf DESCRIPTION
This script uses the Lire::Syslog module to create a DLF representation of the syslog log files. It can process all the syslog log formats supported by that module. EXAMPLES
To process a log as produced by syslog: $ syslog2dlf < syslog.log syslog2dlf will be rarely used on its own, but is more likely called by lr_log2report: $ lr_log2report syslog < /var/log/syslog.log SEE ALSO
Lire::Syslog(3pm) VERSION
$Id: syslog2dlf.in,v 1.6 2006/07/23 13:16:36 vanbaal Exp $ AUTHOR
Francis J. Lacoste <flacoste@logreport.org> COPYRIGHT
Copyright (C) 2002 Stichting LogReport Foundation LogReport@LogReport.org This program is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. Lire 2.1.1 2006-07-23 SYSLOG2DLF.IN(1)
All times are GMT -4. The time now is 12:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy