BASH condition for "File older than 1 hour"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH condition for "File older than 1 hour"
# 1  
Old 02-16-2009
BASH condition for "File older than 1 hour"

I have a monitor script that executes every 5 minutes. I am adding functionality that will detect if a previous execution is hung. I have managed to do that by using a flag that is created when the monitor starts and is then removed when the monitor finishes. The hang check simply looks to see if the flag exists and if it does, trigger an alert. Problem is, if a monitor hangs, every subsequent execution shoots off an alert every 5 mins (that's 96 alerts in the morning if it hangs just after I go to bed...)

So, what I need is a second test that will check to see if the flag is older than 1 hour. That way I'll get the initial alert and then one every hour after that instead of every 5 mins. I need a simple condition for my script:

Code:
if [ -a monitor_running_flag ]
then
   if [ -a hung_monitor_flag ]
      echo "alert fired already"
   else
      echo "previous execution of monitor might be hung"
      touch hung_monitor_flag
   fi  
fi

if [ monitor_running_flag older than 1 hour ]
then
   echo "monitor still hung, check on it"
fi

I need something for: [ monitor_running_flag older than 1 hour ]

Thanks!
# 2  
Old 02-16-2009
Tools An approach to think about

We get lots of requests dealing with date/time on this board. In fact, I replied to a request for week-old date just recently.
https://www.unix.com/shell-programmin...ious-date.html

Perhaps change around a little of that logic to only compare the return numerical value fro the stat-c command to stat -c minus (60*60) for one hour.

Does that make sense?
# 3  
Old 02-16-2009
Thanks. Though I came up with this, seems to work well:

Code:
if test `find monitor_running_flag -mmin +60`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Explaining behaviour of sudo bash "$0" "$@";

I've found this script part on the stackoverflow: if ; then sudo bash "$0" "$@"; exit "$?"; fi I realized that sudo bash "$0" "$@"; is the only needed for me. But the strange thing happens when I move this line outside the IF statement: sudo bash "$0" "$@"; stops the... (9 Replies)
Discussion started by: boqsc
9 Replies

3. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. UNIX for Dummies Questions & Answers

"Help with bash script" - "License Server and Patch Updates"

Hi All, I'm completely new to bash scripting and still learning my way through albeit vey slowly. I need to know where to insert my server names', my ip address numbers through out the script alas to no avail. I'm also searching on how to save .sh (bash shell) script properly.... (25 Replies)
Discussion started by: profileuser
25 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

8. Shell Programming and Scripting

Delete files older than "x" if directory size is greater than "y"

I wrote a script to delete files which are older than "x" days, if the size of the directory is greater than "y" #!/bin/bash du -hs $1 while read SIZE ENTRY do if ; then find $1 -mtime +$2 -exec rm -f {} \; echo "Files older than $2 days deleted" else echo "free Space available"... (4 Replies)
Discussion started by: JamesCarter
4 Replies

9. Shell Programming and Scripting

Script for delete tmp files older than 15 days and owned by "xxx" id

Hi All , I want to delete files from /tmp directory created by "xxxx" id. because i got the list says more than 60 thousand files were created by "xxxx" id since 2002. The /tmp directory has lot of files created by different user ids like root,system etc.. But, i need a script to... (2 Replies)
Discussion started by: vparunkumar
2 Replies

10. HP-UX

IF Condition in ".sh" File (Beginner)

Hi, I have the below ".sh" file which I just need to put an IF condition to exit from the file/code. Please see the remarks in the code below: #!/bin/sh currentdatehour=`date '+%Y-%m-%d-%H'` hh=`date '+%H'` currenthour=`expr ${hh} - 0` onehourback=`expr ${hh} - 1` twohoursback=`expr... (2 Replies)
Discussion started by: salanalani
2 Replies
Login or Register to Ask a Question