![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| waiting | mpang_ | Shell Programming and Scripting | 1 | 10-04-2007 02:52 AM |
| Waiting between commands | patwa | UNIX for Dummies Questions & Answers | 1 | 06-16-2007 02:01 PM |
| Process(s) ID waiting on IO? | Citrus143 | UNIX for Advanced & Expert Users | 9 | 03-29-2007 05:28 PM |
| Waiting on a group | tphyahoo | Shell Programming and Scripting | 1 | 05-24-2006 05:19 PM |
| waiting process | shukla_chanchal | Linux | 2 | 11-03-2005 07:00 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Looping and waiting
Hi Is it possible to have a script run in a loop (waiting for a change of state in the network interface), and if the loop continues for five minutes, to have it email the admin, and carry on in the loop? Here is my loop: Code:
#!/bin/bash
STATE=`echo "show State:/Network/Interface/bond0/Link" | scutil | grep -c "TRUE"`
while [ ! ${STATE} -eq 1 ]
do
echo "Link is inactive"
/bin/sleep 2
done
echo "Link is alive"
If this is possible, how would I achieve it? Mike |
|
||||
|
#!/bin/bash
STATE=`echo "show State:/Network/Interface/bond0/Link" | scutil | grep -c "TRUE"` while [ ! ${STATE} -eq 1 ] do echo "Link is inactive" /bin/sleep 2 STATE=`echo "show State:/Network/Interface/bond0/Link" | scutil | grep -c "TRUE" done echo "Link is alive" |
|
||||
|
Hey all As a follow-up, I figured it out. So, if anyone is searching for a similar solution, here is my proposed script in its entireity. It is used within OS X. Note that after 5 minutes, I actually exit the script and do not continue: Code:
#!/bin/bash
# Script to call external monitor scripts
# This is run via Launchd
###
# Setup Email
###
C_NAME=`/usr/sbin/scutil --get ComputerName`
NOTIFY="admin@admin.com"
WARNING="There is a problem with the NIC's on the primary Moodle server."
###
# End setup Email
###
TIME="0"
# The loop is for 150 times
# 150x2(sleep time)=300s=5minutes
# If this script continues to fail
# after 5 minutes it will finish the loop
# and then email the admin with necessary info
while [ ${TIME} -ne 150 ]
do
# Sleep for 2 seconds in between to preserve
# processor hogging
/bin/sleep 2
# Check state of aggregated link and interfaces associated
# with it. Apache will not run unitl NICs are up and running
# so the remainder of this script will fail.
if [ ! $(echo "show State:/Network/Interface/bond0/Link" | scutil \
| grep -c "TRUE") -eq 1 ]
then
echo Loop ${TIME}
echo "Interface is not active"
TIME=$(( ${TIME} + 1 ))
else
echo "Interface is alive"
# Sleep to allow Apache time to start.
# If Apache fails after this amount of
# time, then there is something wrong
# and shutdown_services script will be
# called to initiate failover
/bin/sleep 30
echo "Running monitor scripts"
# Call check_apache.sh script
APACHE="/Library/IPFailover/scripts/check_apache.sh"
if [ -x ${APACHE} ]
then
/Library/IPFailover/scripts/check_apache.sh
else
echo "check_apache.sh does not exist - moving to next script"
logger \
"FAILOVER: check_apache.sh does not exist - moving to next script"
fi
# Call check_php.sh script
PHP="/Library/IPFailover/scripts/check_php.sh"
if [ -x ${PHP} ]
then
/Library/IPFailover/scripts/check_php.sh
else
echo "check_php.sh does not exist - moving to next script"
logger \
"FAILOVER: check_php.sh does not exist - moving to next script"
fi
# Call check_postgres.sh script
POSTGRES="/Library/IPFailover/scripts/check_postgres.sh"
if [ -x ${POSTGRES} ]
then
/Library/IPFailover/scripts/check_postgres.sh
else
echo "check_postgres.sh does not exist - moving to next script"
logger \
"FAILOVER: check_postgres.sh does not exist - moving to next script"
fi
# Exit the script and therefore the loop
# Using "break" would only exit the loop
# and not exit the script
# We don't need to email Admins
# when the script is successful
exit 0
fi
done
echo "Finished looping"
echo "Mailing the admin"
logger "FAILOVER: Problem with Network Interfaces - mailing the admin and exiting monitor.sh script"
# Mail the System Administrator
echo From: $C_NAME - ${WARNING} > /tmp/monitor_warning.txt
echo ----- >> /tmp/monitor_warning.txt
echo "Note that there has been a bad response from the "monitor" shell script."\
>> /tmp/monitor_warning.txt
echo "This means that there is a problem with the Network Interfaces of $C_NAME providing the Moodle service." \
>> /tmp/monitor_warning.txt
echo ----- >> /tmp/monitor_warning.txt
echo "This error was written out at `date`." >> /tmp/monitor_warning.txt
echo ----- >> /tmp/monitor_warning.txt
echo "Please attend to this immediately." >> /tmp/monitor_warning.txt
cat /tmp/monitor_warning.txt | mail -s \
"From: ${C_NAME} - Primary NIC's are down" ${NOTIFY}
# Should I instigate failover here?
exit 0
Hope this is of some use to someone. Mike Last edited by mikie; 11-29-2006 at 05:10 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|