LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-05-2011, 03:35 PM   #1
dsevern
LQ Newbie
 
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
Monitoring shell script


I'm having to write a script to make up for a command line products shortfalls.

The command will kick off multiple background processes, the number of processes is based on the number of filenames in a given file; workspace.lst.

Each process will create a logfile with the same name as the input filename in a directory; LOG_DIR.

I don't know how long it will take each process to complete, but for this exercise I can assume no more than 1 hour.

I need to grep each log filename in workspaces.lst in LOG_DIR for the existance of a "Success" string. If it exists, processing for that filename is done and check the others. If it doesn't I want to wait 5 minutes and check again. If after 60 minutes all are complete, exit. Or if after 60 minutes some logfiles do not contain the success string, assume failure.

I can't even seem to pseudo-code this, much less bash script it. If anyone is bored and has some time, your help would be greatly appreciated.

Last edited by dsevern; 01-05-2011 at 03:37 PM.
 
Old 01-05-2011, 05:36 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
I think this should work...

Code:
#!/bin/bash

x=11
LOG_DIR="/here/be/logs"
cd $LOG_DIR
while [ $x -ge 0 ] 
do
	finished=1
	for f in *
	do
		grep Success "$f" >/dev/null
		if [ "$?" -gt 0 ]; then
			finished=0
		fi
	done
	
	if [ "$finished" -eq 1 ]; then
		echo "Success"
		exit 0
	fi

	sleep 300 
	let x-=1
done

kill -9 `ps aux | grep the_process | egrep -v grep | awk '{print $2}'`
echo "Failure"
exit 1
EDIT: What does it say about my life that the first thing I thought when I woke up this morning was "I missed a line in the code I wrote last night?". The script has been amended to kill all of the processes before reporting failure.

Last edited by Snark1994; 01-06-2011 at 02:10 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
Shell script for monitoring HariharanV Linux - Software 3 10-04-2010 09:10 AM
Shell script for monitoring a list of IP's HariharanV Linux - Software 26 09-20-2010 06:39 AM
Korn Shell problem / User Monitoring script Fragments Programming 1 03-18-2010 07:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration