#!/bin/bash

function ppp_check()
{
	config_list=`ls /etc/sysconfig/network-scripts/ifcfg-ppp*|grep "/etc/sysconfig/network-scripts/ifcfg-ppp[1-9]*[0-9]*$"|sort -Vk 1`
	config_num=`ls /etc/sysconfig/network-scripts/ifcfg-ppp*|grep "/etc/sysconfig/network-scripts/ifcfg-ppp[1-9]*[0-9]*$"|sort -Vk 1|wc -l`
	for config in $config_list
	do 
		clo=`echo $config | sed "s/\/etc\/sysconfig\/network-scripts\/ifcfg-ppp//g"`
		connect_status=`/usr/bin/ps aux|grep "/sbin/pppoe-connect $config\$"|wc -l`
		#echo connect_status:$connect_status
		#2022/11/14 Link is attached to ppp-ppp, but ppp-ppp is down
		status_status=`/usr/sbin/pppoe-status $config | grep "but" | grep "is down"|wc -l`
		if [[ $connect_status -lt 1  || ${status_status} -gt 0 ]];then
			echo "status_status:"${status_status} "/usr/sbin/pppoe-status $config"
			pppd_status=`/usr/bin/ps -ef|grep "/usr/sbin/pppd ipparam ppp${clo} linkname ppp${clo} plugin"|grep -v "grep"|wc -l`
			#echo pppd_status:$pppd_status
			if [[ $pppd_status -lt 1 ]];then
				/usr/sbin/ifup ppp${clo}&
			else
				pid=`/usr/bin/ps -ef |grep "/usr/sbin/pppd ipparam ppp${clo} linkname ppp${clo} plugin"|grep -v "grep"|awk '{print $2}'`
				#echo pid:$pid
				/usr/bin/kill $pid
				/usr/sbin/ifup ppp${clo}&
				sleep 1
			fi
		fi
	done
}

ppp_check
