Initial import
This commit is contained in:
95
test_email.sh
Executable file
95
test_email.sh
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||
|
||||
datum=`/bin/date +"%d.%m.%Y"`
|
||||
|
||||
email_to=$1
|
||||
email_to=${email_to:="root"}
|
||||
|
||||
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_IP=`ifconfig | grep -A 1 $INET_INTERFACE | grep "inet Adresse" | cut -d":" -f2 | cut -d " " -f1`
|
||||
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}'`;
|
||||
|
||||
echo "" > $file
|
||||
echo " *******************************************************" >> $file
|
||||
echo " *** This is an autogenerated mail ***" >> $file
|
||||
echo "" >> $file
|
||||
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
|
||||
fi
|
||||
fi
|
||||
else
|
||||
if [ "$INET_INTERFACE" ];then
|
||||
echo -e "\tInterface extern.............: $INET_INTERFACE" >> $file
|
||||
echo "" >> $file
|
||||
declare -i i=1
|
||||
for ip in $EXTERN_IP ; do
|
||||
if [ $i -eq 1 ]; then
|
||||
echo -e "\tLocal IPv4 address...........: $ip" >> $file
|
||||
else
|
||||
echo -e "\t $ip" >> $file
|
||||
fi
|
||||
let i++
|
||||
done
|
||||
fi
|
||||
fi
|
||||
echo "" >> $file
|
||||
if [ "$DEFAULT_GW" ] ; then
|
||||
echo -e "\tDefault Gateway..............: $DEFAULT_GW" >> $file
|
||||
fi
|
||||
echo "" >> $file
|
||||
declare -i i=1
|
||||
for dns in $DNS_SERVER ; do
|
||||
echo -e "\tNameserver $i.................: $dns" >> $file
|
||||
let i++
|
||||
done
|
||||
echo "" >> $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
|
||||
|
||||
|
||||
rm -f $file
|
||||
|
||||
Reference in New Issue
Block a user