KSH Script to watch log files for 2 strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH Script to watch log files for 2 strings
# 1  
Old 08-22-2010
KSH Script to watch log files for 2 strings

Hi all,

How can I do a ksh script to watch a log file for 2 specific alarms that have one this string : "Connection Error" and the other one: "Failure in sending". I would like to watch for these two alarms in the log and then if each of them repeats for about 30 times to go kill 2 processes.

Thanks,
# 2  
Old 08-22-2010
I know some of ksh but I'm not yet used to it so I wrote this in bash. I hope you at least get the concept:
Code:
#!/bin/bash

LOGFILE=<path to logfile>

C0=$(fgrep -c 'Connection Error' "$LOGFILE")
F0=$(fgrep -c 'Failure in sending' "$LOGFILE")

function killProcs {
	...
}

while sleep 40s; do
	if
		C1=$(fgrep -c 'Connection Error' "$LOGFILE")
		(( C2 = C1 - C0, C0 = C1 ))
		[[ C2 -ge 30 ]]
	then
		killProcs
		# break?
	elif
		F1=$(fgrep -c 'Failure in sending' "$LOGFILE")
		(( F2 = F1 - F0, F0 = C1 ))
		[[ F2 -ge 30 ]]
	then
		killProcs
		# break?
	fi
done


Last edited by konsolebox; 08-22-2010 at 12:08 PM..
This User Gave Thanks to konsolebox For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Shell Programming and Scripting

Watch a directory for files with a pecific pattern

I dont know if this possible. I need to watch a directory and if any file gets appeneded with a particular entry say, nologin.php, we should get output of that. (1 Reply)
Discussion started by: anil510
1 Replies

3. Shell Programming and Scripting

Watch a directory for new files

In Solaris, and other distros without the "watch" command, use the following code watch for files added to a directory. #!/bin/bash while ; do watchdir=/var/tmp newfile=$watchdir/.newer touch $newfile find $watchdir -newer $newfile; touch -a -m $newfile; ... (10 Replies)
Discussion started by: os2mac
10 Replies

4. Shell Programming and Scripting

Moving log files based on month - help with ksh shell script

Hello, I'm trying to move the log files from the parent directory to respective monthly folder and I would be running this script on a weekly basis through cron. I'm new to this scripting and here is what i could come up and it runs without really doing anything. I even tried placing echo... (2 Replies)
Discussion started by: jusblues
2 Replies

5. Shell Programming and Scripting

Script to find NOT common strings in two files

Hi all, I'd like you to help or give any advise about the following: I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2: file1: errormsgadmin esdp esgservices esignipa iprice ipvpn irm... (18 Replies)
Discussion started by: hnux
18 Replies

6. Shell Programming and Scripting

Script to find NOT common strings in two files

Hi all, I'd like you to help or give any advise about the following: I have two (2) files, file1 and file2, both files have information common to each other. The contents of file1 is a subset of the contents of file2: file1: errormsgadmin esdp esgservices esignipa iprice ipvpn irm... (0 Replies)
Discussion started by: hnux
0 Replies

7. Shell Programming and Scripting

Simple script to find common strings in two files

Hi , I want to write a simple script. I have two files file1: BCSpeciality Backend CB CBAPQualDisp CBCimsVFTRCK CBDSNQualDisp CBDefault CBDisney CBFaxMCGen CBMCGeneral CBMCQualDisp file2: CSpeciality Backend (8 Replies)
Discussion started by: ramky79
8 Replies

8. Shell Programming and Scripting

ksh-script "arithmetic syntax error" comparing strings

Hi all, Iīve already searched the forum but canīt find what i am doing wrong. I am trying to compare two variables using ksh under red hat. The error I get is: -ksh: .: MDA=`md5sum /tmp/ftp_dir_after_transfer | cut -d' ' -f1 ` MDB=`md5sum /tmp/ftp_dir_before_transfer | cut -d' ' -f1 `... (3 Replies)
Discussion started by: old_mike
3 Replies

9. UNIX for Dummies Questions & Answers

Which log files to watch for size?

I'm rusty with unix admin, and I was just informed by a peer in another city that I need to watch my unix log files for size, but she never told me which ones to watch - and of course, now she's gone for two weeks! I am using Sco OpenServer 5.5 (I believe), can anyone tip me off on the trouble log... (3 Replies)
Discussion started by: citygov
3 Replies

10. Shell Programming and Scripting

ksh script to analyze log files on AIX 5.2

Hi, I have written a script that traps errors on different servers from the log files based on the current system date. The trapped errors are written to a file and file is sent as an attachment to an email. I would like to run this script for every 2hrs. when i run the script from the second... (0 Replies)
Discussion started by: itzcoolbuddy
0 Replies
Login or Register to Ask a Question