maniu@securebrain.com:~/script# cd baracca/
maniu@securebrain.com:~/script/baracca# cat baracca.sh virtual_ip.sh cron_rsync.sh rsync.sh
# cat baracca.sh
#!/bin/bash
DIRPWD=/usr/local/script
case "$1" in
'apri' )
$DIRPWD/virtual_ip.sh start && $DIRPWD/apache start && $DIRPWD/tomcat start && echo -e "\\e[1;32mTomcat and Apache started... enjoy!\\e[0m"
;;
'chiudi' )
$DIRPWD/apache stop && $DIRPWD/tomcat stop && $DIRPWD/virtual_ip.sh stop && echo -e "\\e[1;32mTomcat and Apache stopped...!\\e[0m"
;;
'stato' )
$DIRPWD/virtual_ip.sh status
TOMCAT_PID=`cat /usr/local/tomcat/tomcat.pid`
if [ `ps -p $TOMCAT_PID -f |grep -q tomcat; echo $?` -eq 0 ]
then echo -e "\\e[1;32m-- Tomcat is up and running with PID $TOMCAT_PID...!\\e[0m"
else echo -e "\\e[0;31m-- Tomcat is down..\\e[0m"
fi
APACHE_STAT=`/usr/sbin/apachectl status|grep "Sinistri"`
if [ -n "$APACHE_STAT" ]
then echo -e "\\e[1;32m-- Apache is up and running...!\\e[0m"
else echo -e "\\e[0;31m-- Apache is down..\\e[0m"
fi
;;
*)
echo "Usage: $(basename $0) apri|chiudi|stato"
;;
esac
# cat virtual_ip.sh
#!/bin/bash
VIRTUAL_IP="ip.del.finto.logicalhost"
NETMASK="netmask.del.finto.logicalhost"
BROADCAST="broadcast.del.finto.logicalhost"
STATUS=999
case "$1" in
'start' )
echo "Activating virtual IP..."
/bin/ping -c 5 ${VIRTUAL_IP} || /sbin/ifconfig eth1:1 ${VIRTUAL_IP} netmask ${NETMASK} broadcast ${BROADCAST} up
STATUS=0
;;
'stop' )
echo "Deactivating virtual IP..."
/sbin/ifconfig eth1:1 down
STATUS=0
;;
'status' )
if [ $(/sbin/ifconfig -a eth1:1|grep -q $VIRTUAL_IP; echo $?) -eq 0 ] ; then
echo -e "\\e[1;32m-- Virtual IP is configured!\\e[0m"
STATUS=10
else
echo -e "\\e[0;31m-- Virtual IP isn't configured!\\e[0m"
STATUS=11
fi
;;
*)
echo "Usage: $(basename $0) start|stop|status"
STATUS=99
;;
esac
exit $STATUS
# cat cron_rsync.sh
#!/bin/bash
/usr/local/script/virtual_ip.sh status
STATUS=$(echo $?)
if [ $STATUS -eq 10 ] ; then
/usr/local/script/rsync.sh
echo -e "\\e[1;32m-- Rsync done!\\e[0m"
else
echo -e "\\e[0;31m-- I haven't got virtual IP! Nothing to do\\e[0m"
fi
# cat rsync.sh
#!/bin/sh
LOG=/usr/local/log/rsync.log
> $LOG
FILE=/usr/local/script/syncronized_files.txt
HOST=`hostname`
if [ "$HOST" = "myhost1" ]
then
DEST=myhost2
else
if [ "$HOST" = myhost2 ]
then
DEST=myhost1
fi
fi
echo "===================================================================================" >> $LOG
echo `date` : starting syncronization from $HOST to $DEST >> $LOG
for i in `cat $FILE |grep -v ^#`
do
/usr/bin/rsync --timeout=60 -av --update $i $DEST-priv:$i >> $LOG || echo "Careful analysis \
of data in your log files $LOG can give you lots of information" | /usr/bin/mailx -s "$HOST : rsync error" root@$HOST.mydomain
done