Scripting

Bash Examples

#!/bin/bash

ANT_HOME=/usr/local/ant; export ANT_HOME
JAVA_HOME=/usr/java; export JAVA_HOME
PATH=$PATH:$ANT_HOME/bin; export PATH

echo "----------------------"
echo
echo "slow_restart0 starting"
date
echo
echo "----------------------"

rm -f /export/home/orion/log/slow_restart0.out
`ps -eo pid,args | grep "path=/export/home/orion.0.0" | grep -v grep > /export/home/orion/log/slow_restart0.out`

mcount=`cat /export/home/orion/log/slow_restart0.out | wc -l`
if [ $mcount -gt 1 ]
then
echo "Both orions running - can't flip"
echo "Both orions are running - can't flip-flop!" | mail -s "Can't flip-flop Server 5050/6060 both orions are running!" jez@jez.com

elif [ $mcount = 0 ]
then
################# No orions running - starting 6060 ################
echo "No orions running - starting 6060"
/export/home/orion/start_orion.sh 6060
while [ "`tail -5 /export/home/orion6060/log/output.log | grep 'Orion/1.5.2 initialized'`" != 'Orion/1.5.2 initialized' ]
do
sleep 0.5
done
/export/home/orion/redirect0.sh 6060

else

cat /export/home/orion/log/slow_restart0.out | while read LINE
do
if [ `echo $LINE | awk '{print $5}'` = '-Dp6.home=/export/home/orion5050/lib' ]
then
################# Redirect to 6060 ################
/export/home/orion/start_orion.sh 6060
while [ "`tail -5 /export/home/orion6060/log/output.log | grep 'Orion/1.5.2 initialized'`" != 'Orion/1.5.2 initialized' ]
do
sleep 0.5
done
#/home/orion/spinup.sh 6060
echo "Redirect to 6060"
/export/home/orion/redirect0.sh 6060
echo "Sending Termination Signal to pid" `ps -eo pid,args | grep "path=/export/home/orion5050" | grep -v grep | awk '{print $1}'`

ps -eo pid,args | grep "path=/export/home/orion5050" | grep -v grep | awk '{print $1}' |xargs -n1 kill -9


elif [ `echo $LINE | awk '{print $5}'` = '-Dp6.home=/export/home/orion6060/lib' ]
then
################# Redirect to 5050 ################
/export/home/orion/start_orion.sh 5050
while [ "`tail -5 /export/home/orion5050/log/output.log | grep 'Orion/1.5.2 initialized'`" != 'Orion/1.5.2 initialized' ]
do
sleep 0.5
done
#/home/orion/spinup.sh 5050
echo "Redirect to 5050"
/export/home/orion/redirect0.sh 5050
echo "Sending Termination Signal to pid" `ps -eo pid,args | grep "path=/export/home/orion6060" | grep -v grep | awk '{print $1}'`

ps -eo pid,args | grep "path=/export/home/orion6060" | grep -v grep | awk '{print $1}' |xargs -n1 kill -9



fi
done
fi
exit