LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-08-2007, 10:23 AM   #1
csdhiman
Member
 
Registered: Mar 2007
Posts: 47

Rep: Reputation: 15
bash scripting


dear all
i am using fedora 4 for bash scripting
i have a postfix mail server . my script run on this server

i want to make a sript which will manage server automatically
for this a make script which will mail me if queue greater the 500
as:

#!/bin/bash
qshape|head|grep TOTAL|awk '/.*/ {print $2}' >value
i=`cat value`
if [ "$i" -gt 500 ];
then
mail -s "`date` " cs_dhiman@yahoo.co.in < output
cp /etc/postfix/main.cf.bk /etc/postfix/main.cf
postfix reload
fi

this works ok .
the cp line in script will place a file which has default_process limit as 25
now i want that after 5 min. the main.cf.ok will replace the main.cf

so that the default _process limit will become 700 .( as in normal mode)

Question is:
what type loop will help me to calculate 5 min time after the if condition comes true ...so that i can put the orignal file...
 
Old 10-08-2007, 11:49 AM   #2
Wells
Member
 
Registered: Nov 2004
Location: Florida, USA
Distribution: Debian, Redhat
Posts: 417

Rep: Reputation: 53
I guess you could use the sleep command. From the man page:

Quote:
NAME
sleep - delay for a specified amount of time

SYNOPSIS
sleep NUMBER[SUFFIX]...
sleep OPTION

DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the
default), ‘m’ for minutes, ‘h’ for hours or ‘d’ for days. Unlike most
implementations that require NUMBER be an integer, here NUMBER may be
an arbitrary floating point number.

--help display this help and exit

--version
output version information and exit
 
Old 10-08-2007, 01:14 PM   #3
andyccn
Member
 
Registered: Aug 2006
Distribution: Fedora 7
Posts: 46

Rep: Reputation: 15
Personally I'd look at doing this in a proper monitoring system, such as Nagios.
Nagios can run scripts as event handlers - it can run a script once when your mail queue goes over 500, then keep checking at regular intervals, and run another script when it falls back below 500.

You could even do it at 2 levels - so if the mail queue is between 400 and 500, then lower the process limit to 500, if it's over 500, lower it to 25 etc, if it falls back below 400 then raise it to 700 again, or whatever.

But then that's just me ;-)
 
Old 10-12-2007, 12:15 AM   #4
csdhiman
Member
 
Registered: Mar 2007
Posts: 47

Original Poster
Rep: Reputation: 15
Thanks for reply

i did it with the script for all of u is :

#!/bin/bash
TIME_LIMIT=300
INTERVAL=1
while [ "$SECONDS" -le "$TIME_LIMIT" ]
do
if [ "$SECONDS" -lt 300 ]
then
units=second
else
[my script path ]
fi
sleep $INTERVAL
done
exit 0


this works ok
 
  


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
Bash scripting disruptive Programming 5 06-29-2006 03:49 PM
Bash Scripting paranoid times Programming 4 02-15-2006 10:48 AM
BASH Scripting akilles Linux - Newbie 5 11-10-2004 07:26 PM
BASH If-then-else Scripting Help xianzai Programming 4 10-29-2004 04:09 AM
help with bash scripting spuzzzzzzz Programming 2 09-02-2004 11:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:30 AM.

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