sedlo |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bash
# author : Petr Simandl www.simandl.cz
# release date : 19/08/2004
# name : sedlo
# description : dynamic side routing tables tool
# license : GPL
sl_version="0.0.1"
PATH=$PATH:$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin
sl_nmcnf="sedlo.conf"
sl_sedlocnf="/etc/$sl_nmcnf"
sl_sedlocache="/var/cache/sedlo"
sl_rttab="/etc/iproute2/rt_tables"
sl_rtnmin=110
sl_rtnmax=125
sl_ipcmd=`which wget`
sl_hnmcmd=`which hostname`
sl_awkcmd=`which awk`
sl_time=`date '+%Y%m%d%H%M%S'`
if [ -e $sl_sedlocnf ]
then
sl_nop=1
else
echo "$sl_sedlocnf not found"
exit 1
fi
if [ -e $sl_rttab ]
then
sl_nop=1
else
echo "$sl_rttab not found"
exit 1
fi
sl_murlcfg=`cat $sl_sedlocnf | grep mcnf | uniq | awk '{print $2}'`
######################################################################
s_mktables()
{
echo s_mktables
sl_igws=`cat $sl_sedlocache/$sl_nmcnf | grep "^igw" | awk '{print $3}'`
for sl_igw in $sl_igws
do
sl_igwrttb=`cat $sl_rttab | awk '{print $2}' | grep $sl_igw `
if [ "$sl_igwrttb x" = " x" ]
then
echo "Table for $sl_igw not found - creating"
sl_cnt="$sl_rtnmax"
sl_ok="no"
until [ "$sl_cnt" -eq "$sl_rtnmin" ] || [ "$sl_ok" = "yes" ]
do
#space is used to recognized two and three digit numbers
sl_igwrttb=`cat $sl_rttab | awk '{print $1" "}' | grep "$sl_cnt " `
if [ "$sl_igwrttb x" = " x" ]
then
sl_ok="yes"
echo "$sl_cnt $sl_igw" >> $sl_rttab
fi
sl_cnt=$(($sl_cnt - 1 ))
done
else
echo "Table for $sl_igw found"
fi
done
}
######################################################################
s_getcfg()
{
echo s_getcfg
wget $sl_murlcfg -O "$sl_sedlocache/$sl_nmcnf.main" -q
echo "# generated file" > $sl_sedlocache/$sl_nmcnf
for sl_file in `ls $sl_sedlocnf $sl_sedlocache/$sl_nmcnf.main `
do
cat $sl_file | grep "^mcnf" | awk '{print $1"\t"$2}' >> $sl_sedlocache/$sl_nmcnf
cat $sl_file | grep "^igw" | awk '{print $1"\t"$2"\t"$3}' >> $sl_sedlocache/$sl_nmcnf
cat $sl_file | grep "^ip" | awk '{print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6}' >> $sl_sedlocache/$sl_nmcnf
done
cat $sl_sedlocache/$sl_nmcnf | sort | uniq > $sl_sedlocache/$sl_nmcnf.uniq
mv $sl_sedlocache/$sl_nmcnf.uniq $sl_sedlocache/$sl_nmcnf
}
######################################################################
s_version()
{
echo sedlo $sl_version
exit 0
}
######################################################################
s_help()
{
echo Pouziti: sedlo [param]
echo param:
echo -v vypise verzi
exit 0
}
######################################################################
######################################################################
s_getcfg
s_mktables
exit 0