Don't use 'ifconfig' anymore. Get rid of special ppp handling.

This commit is contained in:
Christoph 2017-09-30 00:01:33 +02:00
parent 044cfaac7c
commit d9c671252c

View File

@ -7,44 +7,19 @@ datum=`/bin/date +"%d.%m.%Y"`
email_to=$1
email_to=${email_to:="root"}
email_from="`whoami`@`hostname --long`"
email_from="$(whoami)@$(hostname --long)"
file=/tmp/mail_ip-up$$
if [ -f /etc/ddclient.conf ]; then
# Check, if this is the interface used for DynDNS (there could be other pppds
eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf`
## - check if interface used by dydns is present
## -
for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do
if [ "$_IFACE" = "$if" ];then
PPP_IFACE=$_IFACE
break
fi
done
fi
if [ "$PPP_IFACE" ] ; then
PPP_REMOTE=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
PPP_LOCAL=`ifconfig $PPP_IFACE 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f2 | cut -d " " -f1`
else
INET_INTERFACE="$(netstat -rn | grep -e"^0.0.0" | awk '{print$8}')"
EXTERN_IPv4="$(ifconfig | grep -A 1 $INET_INTERFACE | grep "inet Adresse" | cut -d":" -f2 | cut -d " " -f1)"
EXTERN_IPv6="$(ifconfig | grep -A 3 $INET_INTERFACE | grep -i global | grep -E "^\s+inet6-" | awk '{print$2}')"
if [[ -z "$EXTERN_IPv4" ]] ; then
EXTERN_IPv4="$(ip addr show $INET_INTERFACE | grep -E "\s+inet\s+" | awk '{print$2}')"
fi
if [[ -z "$EXTERN_IPv6" ]] ; then
EXTERN_IPv6="$(ip addr show $INET_INTERFACE | grep global | grep -E "\s+inet6\s+" | awk '{print$2}')"
fi
INET_INTERFACE="$(netstat -rn | grep -e"^0.0.0" | awk '{print$8}')"
if [[ -n "$INET_INTERFACE" ]] ; then
EXTERN_IPv4="$(ip addr show $INET_INTERFACE | grep -E "\s+inet\s+" | awk '{print$2}')"
EXTERN_IPv6="$(ip addr show $INET_INTERFACE | grep global | grep -E "\s+inet6\s+" | awk '{print$2}')"
fi
DNS_SERVER=`cat /etc/resolv.conf | grep -v -e"^#" | grep nameserver | cut -d " " -f2`
DEFAULT_GW=`netstat -rn | grep -e"^0.0.0" | awk '{print$2}'`;
DNS_SERVER="$(cat /etc/resolv.conf | grep -v -e"^#" | grep nameserver | cut -d " " -f2)"
DEFAULT_GW="$(netstat -rn | grep -e"^0.0.0" | awk '{print$2}')"
echo "" > $file
echo " *******************************************************" >> $file
@ -54,40 +29,28 @@ echo -e "\tHost.........................: `hostname --long`" >> $file
echo "" >> $file
echo -e "\tSender.......................: $email_from" >> $file
echo "" >> $file
if [ "$PPP_IFACE" ] ; then
echo -e "\tInterface name...............: $PPP_IFACE" >> $file
echo -e "\tLocal IP number..............: $PPP_LOCAL" >> $file
echo -e "\tPeer IP number..............: $PPP_REMOTE" >> $file
if [ "$USEPEERDNS" ] && [ "$DNS1" ] ; then
echo -e "\tNameserver 1.................: $DNS1" >> $file
if [ "$DNS2" ] ; then
echo -e "\tNameserver 2.................: $DNS2" >> $file
if [[ -n "$INET_INTERFACE" ]] ; then
echo -e "\tInterface extern.............: $INET_INTERFACE" >> $file
echo "" >> $file
declare -i i=1
for ip in $EXTERN_IPv4 ; do
if [ $i -eq 1 ]; then
echo -e "\tLocal IPv4 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
fi
fi
else
if [ "$INET_INTERFACE" ];then
echo -e "\tInterface extern.............: $INET_INTERFACE" >> $file
echo "" >> $file
declare -i i=1
for ip in $EXTERN_IPv4 ; do
if [ $i -eq 1 ]; then
echo -e "\tLocal IPv4 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
fi
let i++
done
i=1
for ip in $EXTERN_IPv6 ; do
if [ $i -eq 1 ]; then
echo "" >> $file
echo -e "\tLocal IPv6 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
fi
let i++
done
fi
let i++
done
i=1
for ip in $EXTERN_IPv6 ; do
if [ $i -eq 1 ]; then
echo "" >> $file
echo -e "\tLocal IPv6 address...........: $ip" >> $file
else
echo -e "\t $ip" >> $file
fi
let i++
done
fi
echo "" >> $file
if [ "$DEFAULT_GW" ] ; then
@ -100,15 +63,15 @@ for dns in $DNS_SERVER ; do
let i++
done
echo "" >> $file
echo -e "\tDate.........................: `date +\"%d.%m.%Y\"`" >> $file
echo -e "\tTime.........................: `date +\"%H:%M:%S\"`" >> $file
echo -e "\tDate.........................: $(date +"%d.%m.%Y")" >> $file
echo -e "\tTime.........................: $(date +"%H:%M:%S")" >> $file
echo "" >> $file
echo " *** ***" >> $file
echo " *******************************************************" >> $file
echo -e "From:${email_from}\nTo:${email_to}\nSubject:Test on `hostname --long` at $datum\n\n`/bin/cat $file`" | /usr/sbin/sendmail -F '`whoami`' -f $email_from $email_to
echo -e "From:${email_from}\nTo:${email_to}\nSubject:Test on $(hostname --long) at $datum\n\n$(/bin/cat $file)" | /usr/sbin/sendmail -F "$(whoami)" -f $email_from $email_to
rm -f $file
exit 0