linux: shell实例startall.sh

#!/bin/bash -
#########################################################################################
#startAll
#初始化脚本,写入配置,拉起进程
#version:2.1
#dongfeng@baicells.com 20170425
#########################################################################################
##(Note: chmod 744 /home/baicells/eGW/startAll.sh)##

export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/java/jre/bin/:/usr/local/mysql/bin/:/root/bin"

DIR=/home/baicells/eGW/

#替换配置中到EPC的链路IP地址为分配的ipsec地址
cd $DIR
dlipsec=`cat networkcfg.conf |grep "^set_dlipsec_enable" |awk -F " " '{print $2}'`
ulipsec=`cat networkcfg.conf |grep "^set_ulipsec_enable" |awk -F " " '{print $2}'`

if [[ $ulipsec -eq  1 ]];then

while :
do
        ip_conf=`ipsec status | grep client | grep === | awk '{print $2}' | awk 'BEGIN {FS = "/"} {print $1}'`
        if [ -n "$ip_conf" ];then
                echo "$ip_conf"
                break
        fi
        sleep 1
done

sed -i "s#^./lccmd set_gtp_ip uplink add .*#./lccmd set_gtp_ip uplink add $ip_conf#g" config.txt

prereg="^\.\/lccmd set_gwenb_link [0-9]\{1,\} [0-9]\{1,\} "
ipreg="[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}"
postreg=":.*"
sed -i "s/\($prereg\)$ipreg\($postreg\)/\1$ip_conf\2/g"  config.txt

fi

#配置gtp
insmod $DIR"gtp-relay.ko"
gtp_a=`cat networkcfg.conf |grep "^ifconfig gtp1_1 " |awk -F " " '{print $3}' |awk -F "." '{print $1}'`
gtp_b=`cat networkcfg.conf |grep "^ifconfig gtp1_1 " |awk -F " " '{print $3}' |awk -F "." '{print $2}'`
var=`expr $gtp_a \* 256 + $gtp_b`
echo $var > /sys/module/gtp_relay/parameters/gtp_lip

#配置网络
while read line
do
    if [ "${line:0:1}" != "#" ]; then
        [ -z "$line" ] && continue

        $line 2>&1 >/dev/null &

    fi
done < networkcfg.conf


local_forward_flag=`cat networkcfg.conf |grep '^set_local_forwarding' |awk '{print $2}'`
local_forward_port=`cat networkcfg.conf |grep '^set_local_forwarding' |awk '{print $4}'`
local_forward_sourceip=`cat networkcfg.conf |grep '^set_local_forwarding' |awk '{print $6}'`
nat_value=`iptables -nL -t nat |grep SNAT |awk '{if(NR<2){print $1}}'`
echo $local_forward_flag > /sys/module/gtp_relay/parameters/gtp_islip
if [[ $local_forward_flag -eq 1 ]] && [[ $nat_value -eq '' ]];then
    iptables -t nat -A POSTROUTING -s ${gtp_a}.${gtp_b}.0.0/16 -o $local_forward_port -j SNAT --to-source $local_forward_sourceip
fi

if [[ $dlipsec -eq  1 ]];then
    echo 1 > /sys/module/gtp_relay/parameters/gtp_ipsec_dl
else
    echo 0 > /sys/module/gtp_relay/parameters/gtp_ipsec_dl
fi

if [[ $ulipsec -eq  1 ]];then
        echo 1 > /sys/module/gtp_relay/parameters/gtp_ipsec_ul
else
        echo 0 > /sys/module/gtp_relay/parameters/gtp_ipsec_ul
fi

#拉起monitor
cd $DIR
exec=$DIR"monitor"
$exec &
sleep 2

CONFIGFILE=mon.txt
while read line
do
    if [ "${line:0:1}" != "#" ]; then    
        [ -z "$line" ] && continue   
        exename=`echo $line | cut -d' ' -f1` 

    if [[ "$exename" == "./lccmd"  && ! -f $exename ]];then
        
            echo "Unable to execute :: $exename ! file not found"
        fi

    
    $line 2>&1 >/dev/null &
       

    fi
done < $CONFIGFILE   

#后台启动话单上传脚本
./watchdog.sh &

    原文作者:随风化作雨
    原文地址: https://www.jianshu.com/p/fd9cc80b18bf
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞