SMTP záloha
<bash>#!/bin/bash
- IP, kterou nas server natahne na sebe
ROUTE_IP="10.107.3.4"
- IP, ktera bude testovana zda-li na ni bezi smtp
WATCH_IP="10.107.35.1" # yzop.hkfree.org WATCH_PORT="25"
- heslo do zebry
ENAPASS="$(cat /root/smtp-redir-pokus/zebrapass)"
[ "$ENAPASS" == "" ] && { neni definovane zebra heslo! ; exit 1; }
ip_on(){
- nahodime na slave mobilni IP
ifconfig dummy0:40 $ROUTE_IP netmask 255.255.255.255 broadcast $ROUTE_IP up
- nastavime ji do lokalni zebry
cat << EoF | nc localhost zebra > /dev/null free enable $ENAPASS configure terminal ip route $ROUTE_IP/32 127.0.0.1 quit quit
EoF
- pokud zije ssh na master serveru, shodit u nej mobilni IP
nc -w 3 -z $WATCH_IP 22 && ssh lada@yzop.hkfree.org sudo ifdown dummy0:30
}
ip_off(){
- zrusime na slave mobilni IP
ifconfig dummy0:40 down
- smazeme ji z lokalni zebry
cat << EoF | nc localhost zebra > /dev/null free enable $ENAPASS configure terminal no ip route $ROUTE_IP/32 127.0.0.1 quit quit
EoF
- pokud zije ssh na master serveru, nahodit mobilni IP
nc -w 3 -z $WATCH_IP 22 && ssh lada@yzop.hkfree.org sudo ifup dummy0:30 }
- zkusime 2x, jestli port odpovida
master_online(){ nc -w 3 -z $WATCH_IP $WATCH_PORT || nc -w 3 -z $WATCH_IP $WATCH_PORT }
- je mobilni IP na slave stroji?
slave_active(){ cat << EoF | nc localhost zebra | grep -q "$ROUTE_IP" free show ip route static exit
EoF }
- pravidelna kontrola
do_cronjob(){ MASTERUP=0 master_online && MASTERUP=1
SLAVEACT=0 slave_active && SLAVEACT=1
if [ "$MASTERUP" == "0" ]; then if [ "$SLAVEACT" == "0" ]; then echo "Zapinam zalozni IP" ip_on fi fi
if [ "$MASTERUP" == "1" ]; then if [ "$SLAVEACT" == "1" ]; then echo "Vypinam zalozni IP" ip_off fi fi }
case "$1" in cronjob) do_cronjob; exit 0 ;; on) echo Slave prebira veleni; ip_on ; exit 0;; off) echo Slave vraci veleni masterovi; ip_off; exit 0;; test) echo testuju; master_online && echo Master bezi; master_online || echo Master nebezi; exit 0;; active) slave_active || echo Slave neni aktivni; slave_active && echo Slave je aktivni; exit 0;;
- ) echo "usage: $0 cronjob|on|off|test|active";exit 0;;
esac
exit 0 </bash>