Checking if logfile updates after 5 minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking if logfile updates after 5 minutes
# 1  
Old 04-26-2013
Checking if logfile updates after 5 minutes

I would like to create a script that will send an email to me if it does not update after 5 minutes.

I have created this script but it doesn't work.

Code:
#!/bin/ksh
# Variable Declaration
log=/opt/app/netcool/omnibus/log.txt
servertime=`date | awk '{print $2,$3,$4 }' | cut -d ":" -f1,2`
logtime=`ls -ltr $mttrapdlog | awk '{ print $6,$7,$8 }'`
time1=`date | awk '{print $4 }' | cut -d ":" -f2`
time2=`ls -ltr $mttrapdlog | awk '{ print $8 }' | cut -d ":" -f2`
######################## Main Script ########################
if [ $servertime -eq $logtime && `expr $time1 - $time2` -gt 5 ]  
then
mailx -s "Logfile log.txt is not updating for the past 5 minutes." mail.com
fi 
#############################################################

Can someone help me in this script...
Many thanks!

Last edited by joeyg; 04-26-2013 at 08:57 AM.. Reason: Please wrap commands and data in CodeTags
# 2  
Old 04-26-2013
What doesnt work?
What error message do you get?
# 3  
Old 04-26-2013
this is the error when i run it in debug mode

+ [ Apr 26 07:01 -eq Apr 26 06:57
check_mttrapd_log.sh: test: ] missing
# 4  
Old 04-26-2013
Code:
if [ \( $servertime -eq $logtime  \)  &&  \( `expr $time1 - $time2` -gt 5 \) ]

# 5  
Old 04-26-2013
Within [ ] it's -a not &&
# 6  
Old 04-26-2013
Try this:
Code:
if [ $servertime -eq $logtime ] && [ `expr $time1 - $time2` -gt 5 ]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Grep a log file for the last 5 minutes of contents every 5 minutes

Hi all, System Ubuntu 16.04.3 LTS i have the following log INFO 2019-02-07 15:13:31,099 module.py:700] default: "POST /join/8550614e-3e94-4fa5-9ab2-135eefa69c1b HTTP/1.0" 500 2042 INFO 2019-02-07 15:13:31,569 module.py:700] default: "POST /join/6cb9c452-dcb1-45f3-bcca-e33f5d450105... (15 Replies)
Discussion started by: charli1
15 Replies

3. UNIX for Beginners Questions & Answers

How to convert days hours minutes seconds to minutes?

Hi, please help with below time conversion to minutes. one column values: 2 minutes 16 seconds 420 msec 43 seconds 750 msec 0 days 3 hours 29 minutes 58 seconds 480 msec 11 seconds 150 msec I need output in minutes(total elapsed time in minutes) (2 Replies)
Discussion started by: ramu.badugula
2 Replies

4. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

5. Shell Programming and Scripting

Extract the last 10 minutes from logfile

Any better way to extract the last 10 minutes from logfile? Dec 18 09:41:18 aaa Dec 18 09:46:29 aa Dec 18 09:48:39 vvv Dec 18 09:48:54 bbb Dec 18 09:54:47 bbb Dec 18 09:55:33 fcf Dec 18 09:55:38 ssdf Dec 18 09:57:58 sdsds Dec 18 09:58:10 sdsd Dec 18 10:00:50 sdsd Dec 18... (5 Replies)
Discussion started by: timmywong
5 Replies

6. SCO

Stop boot system at "Checking protected password and checking subsystem databases"

Hi, (i'm sorry for my english) I'm a problem on boot sco unix 5.0.5 open server. this stop at "Checking protected password and checking subsystem databases" (See this image ) I'm try this: 1) http://www.digipedia.pl/usenet/thread/50/37093/#post37094 2) SCO: SCO Unix - Server hangs... (9 Replies)
Discussion started by: buji
9 Replies

7. UNIX for Dummies Questions & Answers

Logfile manipulation

Hi First of all I m a complete newbie to Linux ... just started working on it exactly a week ago. I know a bit of programming in C but not very good in it.:D I was given task in my workplace and need some help nAJLR02F030879 9805 Thu Nov 19 13:27 <customerservice@YYY.com> ... (2 Replies)
Discussion started by: abilash.amara
2 Replies

8. Shell Programming and Scripting

logfile

hi iam new of the ksh script.iwant in formation of how to call in logfile in ksh scripts. if the meaning in ksh. please help me thanks naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies

9. Shell Programming and Scripting

Convert minutes to hours, minutes, seconds

How would you convert lets say a 1000 minutes to hours, minutes, seconds (1 Reply)
Discussion started by: Vozx
1 Replies

10. AIX

unix updates- Where can I find unix updates online for IBM servers?

I have a Unix based server running Sagitta and the server is giving me an error of 4b10004 and my research tells me this is an EPROM issue, which means the processor needs to be flashed or repaired. Once up and running where can I go to get updates for Unix? (1 Reply)
Discussion started by: crainer
1 Replies
Login or Register to Ask a Question