Add more checl-scripts
This commit is contained in:
parent
ad7a77eb5a
commit
a97dd2781e
26
OLD/check_amavis.sh
Executable file
26
OLD/check_amavis.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
_check_script="/root/bin/amavis_ckeck.pl"
|
||||
|
||||
if [ -x $_check_script ]; then
|
||||
_check_result=`$_check_script --server 127.0.0.1 --from postmaster --to do-not-reply --port 10024`
|
||||
_retval=$?
|
||||
else
|
||||
echo
|
||||
echo "[ Error ]: Cannot find check script \"$_check_script\""
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$_retval" != "0" ]; then
|
||||
echo
|
||||
echo "[ Error ]: Amavis seems NOT to be running. trying to (re)start service.."
|
||||
echo
|
||||
|
||||
/etc/init.d/amavis stop > /dev/null 2>&1
|
||||
sleep 2
|
||||
/etc/init.d/amavis start > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
324
OLD/check_dsl.sh
Executable file
324
OLD/check_dsl.sh
Executable file
@ -0,0 +1,324 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
## --------------------------
|
||||
## --- Make your changes here
|
||||
## --------------------------
|
||||
|
||||
LOGGING_CONSOLE=false
|
||||
DEBUG=false
|
||||
|
||||
log_file=/var/log/check_dsl.log
|
||||
|
||||
## - Put in your DSL devices (refers to your network configuration)
|
||||
## - youe wish be congigured by that script
|
||||
## -
|
||||
DSL_DEVICES="ppp-surf2 ppp-surf1 ppp-st"
|
||||
|
||||
admin_email=root
|
||||
from_address="check-dsl@`hostname -f`"
|
||||
company="Gemeinschaft Altenschlirf"
|
||||
content_type='Content-Type: text/plain;\n charset="utf-8"'
|
||||
|
||||
##########################################
|
||||
## --- Dont't make changes after this line
|
||||
##########################################
|
||||
|
||||
## ------------------
|
||||
## --- Some functions
|
||||
## ------------------
|
||||
|
||||
## - Check if a given array (parameter 2) contains a given string (parameter 1)
|
||||
## -
|
||||
containsElement () {
|
||||
local e
|
||||
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
|
||||
return 1
|
||||
}
|
||||
|
||||
## -------------------------------------------------
|
||||
## --- If script is already running, stop execution
|
||||
## -------------------------------------------------
|
||||
|
||||
LOCK_DIR=/tmp/`basename $0`.LOCK
|
||||
if mkdir "$LOCK_DIR" 2> /dev/null ; then
|
||||
|
||||
## - Remove lockdir when the script finishes, or when it receives a signal
|
||||
trap 'rm -rf "$LOCK_DIR"' 0 2 15
|
||||
|
||||
else
|
||||
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
msg="[ Error ]: A previos instance of script \"`basename $0`\" seems already be running.\n\n Exiting now.."
|
||||
echo -e "To:${admin_email}\n${content_type}\nSubject:DSL Script Error $company -- $datum\n\n${msg}\n" | /usr/sbin/sendmail -F "DSL Monitoring $company" -f $from_address $admin_email
|
||||
|
||||
if $LOGGING_CONSOLE ; then
|
||||
echo ""
|
||||
echo "[ Error ]: A previos instance script \"`basename $0`\" seems already be running."
|
||||
echo ""
|
||||
echo " Exiting now.."
|
||||
echo ""
|
||||
fi
|
||||
exit 1
|
||||
|
||||
fi
|
||||
|
||||
|
||||
## - Define (non associative) array
|
||||
## -
|
||||
declare -a dsl_devices_arr
|
||||
for _dsl_device in $DSL_DEVICES ; do
|
||||
dsl_devices_arr+=("$_dsl_device")
|
||||
done
|
||||
declare -a online_devices_arr
|
||||
for _online_device in "$@" ; do
|
||||
online_devices_arr+=("$_online_device")
|
||||
done
|
||||
|
||||
## - Define associative array
|
||||
## -
|
||||
declare -A remote_gw_arr
|
||||
declare -A filetime_PID_arr
|
||||
for dsl_device in "${online_devices_arr[@]}" ; do
|
||||
remote_gw_address=`ifconfig $dsl_device 2> /dev/null | grep "inet Adresse" | cut -d":" -f3 | cut -d" " -f1`
|
||||
remote_gw_arr[$dsl_device]=$remote_gw_address
|
||||
_pid_file=/var/run/${dsl_device}.pid
|
||||
if [ -f $_pid_file ]; then
|
||||
filetime_PID_arr[$dsl_device]=`stat -c %Y /var/run/${dsl_device}.pid`
|
||||
else
|
||||
filetime_PID_arr[$dsl_device]="NOT FOUND"
|
||||
fi
|
||||
done
|
||||
|
||||
ping_test_hosts="oopen.de google.com heise.de debian.org ubuntu.com"
|
||||
declare -a ping_ip_arr;
|
||||
|
||||
|
||||
#for _key in "${!filetime_PID_arr[@]}" ; do
|
||||
# echo "filetime_PID_arr[$_key]: ${filetime_PID_arr[$_key]}"
|
||||
#done
|
||||
|
||||
#for _key in "${!remote_gw_arr[@]}" ; do
|
||||
# echo "remote_gw_arr[$_key]: ${remote_gw_arr[$_key]}"
|
||||
#done
|
||||
|
||||
#for _device in ${online_devices_arr[@]} ; do
|
||||
# echo "$_device"
|
||||
#done
|
||||
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] ## ---" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] ## --- Starting script `basename $0`" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] ## --- Devices Online...: ${online_devices_arr[@]}" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] ## --- Remote Gateways..: ${remote_gw_arr[@]}" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] ## ---" >> $log_file
|
||||
|
||||
while true ; do
|
||||
|
||||
changed=false
|
||||
|
||||
for dsl_device in "${dsl_devices_arr[@]}" ; do
|
||||
|
||||
if $DEBUG ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] ## --- Device $dsl_device " >> $log_file
|
||||
fi
|
||||
|
||||
remote_gw_address=`ifconfig $dsl_device 2> /dev/null | grep "inet Adresse" | cut -d":" -f3 | cut -d" " -f1`
|
||||
iface_name="dsl-`echo $dsl_device | cut -d '-' -f2`"
|
||||
rt_name="dsl_`echo $dsl_device | cut -d '-' -f2`"
|
||||
|
||||
if [ -z "$remote_gw_address" ]; then
|
||||
|
||||
if containsElement "$dsl_device" ${online_devices_arr[@]} ; then
|
||||
|
||||
## - <before> <now>
|
||||
## -
|
||||
## - online offline
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Status Devices \"$dsl_device\" changed" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Devices \"$dsl_device\" is now OFFLINE" >> $log_file
|
||||
|
||||
if ps -x | grep -E "/usr/sbin/pppd\s+call\s+$iface_name" > /dev/null 2>&1 ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] pppd for \"$iface_name\" is running: Waiting another period" >> $log_file
|
||||
else
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] Trying to start pppd for \"$dsl_device\".." >> $log_file
|
||||
/usr/sbin/pppd call $iface_name > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
## - Remove device from array online_devices_arr
|
||||
## -
|
||||
for _index in ${!online_devices_arr[@]} ; do
|
||||
if [ "${online_devices_arr[$_index]}" = "$dsl_device" ]; then
|
||||
unset online_devices_arr[$_index]
|
||||
break
|
||||
fi
|
||||
done
|
||||
## - Also remove device from remote_gw_arr
|
||||
## -
|
||||
unset remote_gw_arr[$dsl_device]
|
||||
|
||||
changed=true
|
||||
else
|
||||
## - <before> <now>
|
||||
## -
|
||||
## - offline offline
|
||||
if $DEBUG ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] $dsl_device is still offline" >> $log_file
|
||||
fi
|
||||
|
||||
if ps -x | grep -E "/usr/sbin/pppd\s+call\s+$iface_name" > /dev/null 2>&1 ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] pppd for \"$iface_name\" is running: Waiting another period" >> $log_file
|
||||
else
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] Trying to start pppd for \"$dsl_device\".." >> $log_file
|
||||
/usr/sbin/pppd call $iface_name > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
fi
|
||||
else
|
||||
|
||||
if containsElement "$dsl_device" ${online_devices_arr[@]} ; then
|
||||
|
||||
## - <before> <now>
|
||||
## -
|
||||
## - online online
|
||||
if $DEBUG ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] $dsl_device is still online" >> $log_file
|
||||
fi
|
||||
|
||||
## - Check if remote gateway has changed
|
||||
## -
|
||||
if [ "$remote_gw_address" != "${remote_gw_arr[$dsl_device]}" ]; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Remote Gateway on device \"$dsl_device\" has changed: ${remote_gw_arr[$dsl_device]} --> $remote_gw_address" >> $log_file
|
||||
remote_gw_arr[$dsl_device]=$remote_gw_address
|
||||
filetime_PID_arr[$dsl_device]=`stat -c %Y /var/run/${dsl_device}.pid`
|
||||
changed=true
|
||||
else
|
||||
if $DEBUG ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] Remote Gateway on device \"$dsl_device\": still ${remote_gw_arr[$dsl_device]}" >> $log_file
|
||||
fi
|
||||
|
||||
## - Test if pid-file's modify time hs changed
|
||||
## -
|
||||
## - Notice: that happens if your provider forces a reconnect (mostly one time a day
|
||||
## - or in other words after 1440 minutes)
|
||||
## -
|
||||
_pid_file=/var/run/${dsl_device}.pid
|
||||
if [ -f $_pid_file ]; then
|
||||
if [ "`stat -c %Y $_pid_file`" != "${filetime_PID_arr[$dsl_device]}" ]; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Modify time for pid-file \"${dsl_device}.pid\" has changed" >> $log_file
|
||||
filetime_PID_arr[$dsl_device]=`stat -c %Y $_pid_file`
|
||||
changed=true
|
||||
else
|
||||
|
||||
## - Check if routing through this dsl connection realy works
|
||||
## -
|
||||
failed=true
|
||||
if [ ${#ping_ip_arr[@]} -lt 1 ]; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] No ip-address for ping-test is set. Skipping test.." >> $log_file
|
||||
else
|
||||
for _key in ${!ping_ip_arr[@]} ; do
|
||||
/sbin/ip rule add to ${ping_ip_arr[$_key]} table $rt_name
|
||||
if ping -q -c2 ${ping_ip_arr[$_key]} >/dev/null 2>&1 ; then
|
||||
if $DEBUG ; then
|
||||
_local_gw=`curl -4 https://meine-ip.oopen.de 2> /dev/null`
|
||||
if [ -n "$_local_gw" ]; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] Using local gateway \"$_local_gw\" for ping test" >> $log_file
|
||||
fi
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Debug ] Ping test (to ${ping_ip_arr[$_key]}) for device \"${dsl_device}\" was successful." >> $log_file
|
||||
fi
|
||||
/sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name
|
||||
failed=false
|
||||
break
|
||||
fi
|
||||
/sbin/ip rule del to ${ping_ip_arr[$_key]} table $rt_name
|
||||
done
|
||||
if $failed ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Ping test for device \"${dsl_device}\" failed" >> $log_file
|
||||
i echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Status Devices \"$dsl_device\" changed" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Devices \"$dsl_device\" is now OFFLINE" >> $log_file
|
||||
_pid=`ps -ax | grep -e "pppd call $iface_name" | grep -v grep | awk '{print$1}'`
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Info ] Kill ppp-daemon for $iface_name (pid $_pid)" >> $log_file
|
||||
|
||||
## - Remove device from array online_devices_arr
|
||||
## -
|
||||
for _index in ${!online_devices_arr[@]} ; do
|
||||
if [ "${online_devices_arr[$_index]}" = "$dsl_device" ]; then
|
||||
unset online_devices_arr[$_index]
|
||||
break
|
||||
fi
|
||||
done
|
||||
## - Also remove device from remote_gw_arr
|
||||
## -
|
||||
unset remote_gw_arr[$dsl_device]
|
||||
|
||||
kill -9 $_pid
|
||||
changed=true
|
||||
fi
|
||||
|
||||
fi
|
||||
fi
|
||||
else
|
||||
filetime_PID_arr[$dsl_device]="NOT FOUND"
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] No pid-file for connection \"${dsl_device}\"found" >> $log_file
|
||||
changed=true
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
else
|
||||
## - <before> <now>
|
||||
## -
|
||||
## - offline online
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Status Devices \"$dsl_device\" changed" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Devices \"$dsl_device\" is now online" >> $log_file
|
||||
|
||||
## - Add device to array online_devices_arr
|
||||
## -
|
||||
online_devices_arr+=("$dsl_device")
|
||||
remote_gw_arr[$dsl_device]=$remote_gw_address
|
||||
filetime_PID_arr[$dsl_device]=`stat -c %Y /var/run/${dsl_device}.pid`
|
||||
changed=true
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if $changed ; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Status Online Devices changed" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Online Devices: ${online_devices_arr[@]}" >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Warn ] Reconfigure Routing: invoking script \"netconfig_dsl.sh\".." >> $log_file
|
||||
/root/bin/netconfig_dsl.sh > /dev/null 2>&1
|
||||
#/root/bin/netconfig_dsl_round-robin.sh > /dev/null 2>&1
|
||||
|
||||
datum=`date +"%d.%m.%Y"`
|
||||
msg="[ `date +\"%H:%M:%S\"` ]: Status Online Devices changed..\n Online Devices: ${online_devices_arr[@]}\n\n Script \"netconfig_dsl.sh\" was invoked to reconfigure routing."
|
||||
echo -e "To:${admin_email}\n${content_type}\nSubject:DSL Status changed $company -- $datum\n\n${msg}\n" | /usr/sbin/sendmail -F "DSL Monitoring $company" -f $from_address $admin_email
|
||||
fi
|
||||
|
||||
## - Set IP-adresses for Ping-Test at next run
|
||||
## -
|
||||
if [ ${#online_devices_arr[@]} -gt 0 ]; then
|
||||
ping_test_ip=""
|
||||
unset ping_ip_arr
|
||||
declare -i i=0
|
||||
for _host in $ping_test_hosts ; do
|
||||
while [ $i -lt 2 ]; do
|
||||
ping_test_ip=`dig +short $_host | head -1`
|
||||
if ping -q -c2 $ping_test_ip >/dev/null 2>&1 ; then
|
||||
ping_ip_arr+=("$ping_test_ip")
|
||||
let i++
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [ ${#ping_ip_arr[@]} -lt 1 ]; then
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] No ip-address for ping test found " >> $log_file
|
||||
echo "`date +'%Y-%m-%d %H:%M:%S'` [ Error ] Looked for IP-Addresses at hosts: $ping_test_hosts" >> $log_file
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
sleep 30
|
||||
done
|
||||
|
||||
exit 0
|
48
OLD/check_inet.sh
Executable file
48
OLD/check_inet.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
ptp_addr=`ifconfig ppp0 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
|
||||
alternate_addr="google.com heise.de debian.org ubuntu.com"
|
||||
|
||||
reconnect() {
|
||||
ifdown dsl-provider >/dev/null 2> /dev/null
|
||||
sleep 5
|
||||
killall -9 pppd > /dev/null 2> /dev/null
|
||||
sleep 5
|
||||
ifup dsl-provider >/dev/null 2> /dev/null
|
||||
sleep 5
|
||||
ptp_addr=`ifconfig ppp0 2>/dev/null | grep -e "P-[tz]-P" | cut -d":" -f3 | cut -d " " -f1`
|
||||
if [ "X$ptp_addr" == "X" ] ; then
|
||||
echo "[ Error ]: reconnection host `hostname --long` failed at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
else
|
||||
echo "[ OK ]: `hostname --long` reconnected at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
fi
|
||||
echo ""
|
||||
echo "`df`"
|
||||
}
|
||||
|
||||
if [ "X$ptp_addr" == "X" ] ; then
|
||||
echo "[ Error ]: Internetconnection seems to be down!"
|
||||
echo " Trying to reconnect.."
|
||||
echo ""
|
||||
reconnect
|
||||
else
|
||||
ping -c3 $ptp_addr >/dev/null 2> /dev/null
|
||||
rval=$?
|
||||
if [ $rval -ne 0 ]; then
|
||||
for ip_addr in $alternate_addr ; do
|
||||
ping -c3 $ip_addr >/dev/null 2> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
done;
|
||||
echo "[ Error ]: Internetconnection seems to be down!"
|
||||
echo " Trying to reconnect.."
|
||||
echo ""
|
||||
reconnect
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0;
|
30
OLD/high_load_warning.sh
Normal file
30
OLD/high_load_warning.sh
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
fatal(){
|
||||
echo ""
|
||||
echo -e "Error: $*"
|
||||
echo ""
|
||||
echo -e "\tScript terminated.."
|
||||
echo ""
|
||||
exit 1
|
||||
}
|
||||
## - Number of processors
|
||||
## -
|
||||
declare -i number_processors=`grep -E "processor\s+:\s+" /proc/cpuinfo -c`
|
||||
|
||||
|
||||
if [ -n "$number_processors" -o $number_processors -eq 0 ]; then
|
||||
fatal 'Detecting number of prozessors failed!'
|
||||
fi
|
||||
|
||||
|
||||
if [ $number_processors -gt 8 ]; then
|
||||
|
||||
threshod_1_min=`echo "$number_processors / 2" | bc`
|
||||
threshod_10_min=`echo "$number_processors / 3" | bc`
|
||||
threshod_15_min=`echo "$number_processors / 3" | bc`
|
||||
else
|
||||
threshod_1_min=`echo "$number_processors"`
|
||||
threshod_10_min=`echo "$number_processors /1.5"`
|
||||
fi
|
||||
threshod_15_min=$threshod_10_min
|
22
check_cups.sh
Executable file
22
check_cups.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## - Check if cups service is runnning. If service is down
|
||||
## - start it.
|
||||
## -
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
if ! ps ax | grep /usr/sbin/cupsd | grep -v grep > /dev/null ; then
|
||||
|
||||
echo -e "\n\tCups Daemon is not running. So i'm going to (re)start the cups service..\n"
|
||||
|
||||
/etc/init.d/cups stop
|
||||
|
||||
kill -9 `cat /var/run/cups/cupsd.pid 2>/dev/null` > /dev/null 2>&1
|
||||
rm -f /var/run/cups/cupsd.pid
|
||||
|
||||
## - Start cups daemon
|
||||
/etc/init.d/cups start
|
||||
fi
|
||||
|
||||
exit 0
|
20
check_dns.sh
Executable file
20
check_dns.sh
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
alternate_addr="oopen.de google.com heise.de debian.org ubuntu.com"
|
||||
|
||||
for ip_addr in $alternate_addr ; do
|
||||
ping -c3 $ip_addr >/dev/null 2> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
exit 0
|
||||
fi
|
||||
done;
|
||||
|
||||
/etc/init.d/bind9 restart
|
||||
|
||||
echo ""
|
||||
echo "[ Info ]: Restartet Nameservice bind on host `hostname --long` at `date +\"%d.%m.%Y %H:%M:%S\"`"
|
||||
echo ""
|
||||
|
||||
exit 0;
|
107
check_dyndns.sh
Executable file
107
check_dyndns.sh
Executable file
@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
function usage() {
|
||||
|
||||
echo
|
||||
|
||||
if [ -n "$1" ];then
|
||||
echo -e "Error: $1\n"
|
||||
fi
|
||||
echo -e ""
|
||||
echo -e "\tusage: `basename $0` < dyndns-name>\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
[ $# -eq "0" -o $# -gt "2" ] && usage "wrong number of arguments"
|
||||
|
||||
DYNDNS_NAME=$1
|
||||
|
||||
_SKIP_IP=false
|
||||
|
||||
|
||||
|
||||
|
||||
## - only run ddclient, if it is installed
|
||||
## -
|
||||
if [ ! -x "/usr/sbin/ddclient" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if [ -f "/etc/ddclient.conf" ]; then
|
||||
|
||||
## - read variable "if" from configurationd file "/etc/ddclient.conf"
|
||||
## -
|
||||
eval `sed -n 's/\(if=[^ ,]*\)/\1/p' /etc/ddclient.conf`
|
||||
|
||||
## - check if interface used by dyndns is present
|
||||
##
|
||||
if [ -n "$if" ];then
|
||||
for _IFACE in `ifconfig | grep -e"^ppp" | cut -d" " -f1 `; do
|
||||
if [ "$_IFACE" = $if ];then
|
||||
PPP_IFACE=$_IFACE
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
## - exit if no connection for dydns interface exists
|
||||
## -
|
||||
if [ "X" = "X$PPP_IFACE" ]; then
|
||||
echo "No interface for dydns exists. exiting now.."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
else
|
||||
_SKIP_IP=true
|
||||
fi
|
||||
else
|
||||
## - No configuration file found, so do not run
|
||||
## -
|
||||
echo "No configuration file \"/etc/ddclient.conf\" found, so do not run"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
if ! $_SKIP_IP ; 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`
|
||||
fi
|
||||
|
||||
|
||||
if [ "X$PPP_REMOTE" != "X" -a "X$PPP_LOCAL" != "X" ] ; then
|
||||
|
||||
if $_SKIP_IP ; then
|
||||
|
||||
# Load defaults
|
||||
if [ -f /etc/default/ddclient ]; then
|
||||
|
||||
source /etc/default/ddclient
|
||||
if [ "$run_daemon" = "true" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
/usr/sbin/ddclient
|
||||
|
||||
else
|
||||
|
||||
DYNDNS_IP=`dig $DYNDNS_NAME +short`
|
||||
#echo "$DYNDNS_NAME: $DYNDNS_IP - Local (PPP) IP: $PPP_LOCAL"
|
||||
|
||||
if [ "$DYNDNS_IP" != "$PPP_LOCAL" ] ; then
|
||||
|
||||
## - Run ddclient with the IP address of the ppp device
|
||||
## -
|
||||
echo "try to update ipadress entry at dyndns.org.."
|
||||
echo
|
||||
/usr/sbin/ddclient -syslog -ip $PPP_LOCAL
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
exit 0;
|
17
check_forwarding.sh
Executable file
17
check_forwarding.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
declare -i val=`cat /proc/sys/net/ipv4/ip_forward`
|
||||
|
||||
|
||||
if [ $val == 0 ] ; then
|
||||
echo "activate forwarding .."
|
||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||
fi
|
||||
|
||||
val=`cat /proc/sys/net/ipv4/ip_dynaddr`
|
||||
if [ $val == 0 ] ; then
|
||||
echo "activate dynaddr .."
|
||||
echo 5 > /proc/sys/net/ipv4/ip_dynaddr
|
||||
fi
|
||||
|
||||
exit
|
22
check_ntpd.sh
Executable file
22
check_ntpd.sh
Executable file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## - Check if ntp service is running. (Re)start service, if
|
||||
## - it is down.
|
||||
## -
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
if ! ps ax | grep /usr/sbin/ntpd | grep -v grep > /dev/null ; then
|
||||
|
||||
echo -e "\n\tNTP Daemon is not running. so i'm going to (re)start the ntp service..\n"
|
||||
|
||||
/etc/init.d/ntp stop
|
||||
|
||||
kill -9 `cat /var/run/ntpd.pid 2>/dev/null` > /dev/null 2>&1
|
||||
rm -f /var/run/ntpd.pid
|
||||
|
||||
## - Start ntp daemon
|
||||
/etc/init.d/ntp start
|
||||
fi
|
||||
|
||||
exit 0
|
30
check_resin.sh
Executable file
30
check_resin.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
## - check resin service
|
||||
## -
|
||||
|
||||
PID_SOLR=`ps ax | grep java | grep -e "-jar" | grep start.jar | grep -v grep | awk '{print$1}'`
|
||||
if [ "X${PID_SOLR}X" = "XX" ]; then
|
||||
/etc/init.d/resin-app stop
|
||||
PID_RESIN=`ps aux | grep "/usr/local/resin" | grep -v grep | awk '{print$2}'`
|
||||
while [ "X${PID_RESIN}X" != "XX" ]; do
|
||||
kill -9 $PID_RESIN
|
||||
sleep 1
|
||||
PID_RESIN=`ps aux | grep "/usr/local/resin" | grep -v grep | awk '{print$2}'`
|
||||
done
|
||||
/etc/init.d/resin-app start
|
||||
else
|
||||
PID_RESIN=`ps aux | grep "/usr/local/resin" | grep -v grep | awk '{print$2}'`
|
||||
if [ "X${PID_RESIN}X" == "XX" ]; then
|
||||
/etc/init.d/resin-app stop
|
||||
PID_SOLR=`ps ax | grep java | grep -e "-jar" | grep start.jar | grep -v grep | awk '{print$1}'`
|
||||
while [ "X${PID_SOLR}X" != "XX" ]; do
|
||||
kill -9 $PID_SOLR
|
||||
sleep 1
|
||||
PID_SOLR=`ps aux | grep "/usr/local/resin" | grep -v grep | awk '{print$2}'`
|
||||
done
|
||||
/etc/init.d/resin-app start
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
28
check_samba4_service.sh
Executable file
28
check_samba4_service.sh
Executable file
@ -0,0 +1,28 @@
|
||||
#"!/usr/bin/env bash
|
||||
|
||||
PIDS=`ps aux | grep "/usr/local/samba/sbin/samba" | grep -v grep | awk '{print$2}'`
|
||||
|
||||
if [ "X${PIDS}X" = "XX" ];then
|
||||
echo -e "\n[Error]: Samba Service seems to be down. Try to (re)start .."
|
||||
/etc/init.d/samba4 stop > /dev/null 2>&1
|
||||
/etc/init.d/samba4 start > /dev/null
|
||||
sleep 2
|
||||
NEW_PIDS=`ps aux | grep "/usr/local/samba/sbin/samba" | grep -v grep | awk '{print$2}'`
|
||||
if [ "X${NEW_PIDS}X" = "XX" ]; then
|
||||
echo -e ""
|
||||
echo -e "\t[Error]: Restarting samba services failed !!"
|
||||
echo -e "\n\t[Error]: Restarting samba services failed !!\n"
|
||||
echo -e ""
|
||||
else
|
||||
PIDS=""
|
||||
for pid in $NEW_PIDS ; do
|
||||
PIDS="$PIDS $pid"
|
||||
done
|
||||
echo -e
|
||||
echo -e "\tI have restarted the samba services. The new PIDs are $PIDS"
|
||||
echo -e
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
13
check_vpn.sh
Executable file
13
check_vpn.sh
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
|
||||
if ! ps ax | grep openvpn | grep -v grep > /dev/null ; then
|
||||
echo -e "\n\tOpenVPN is not running. so i'm going to (re)start the vpn service..\n"
|
||||
/etc/init.d/openvpn stop
|
||||
kill -9 `cat /var/run/openvpn.server.pid 2>/dev/null` > /dev/null 2>&1
|
||||
rm -f /var/run/openvpn.server.pid
|
||||
/etc/init.d/openvpn start
|
||||
fi
|
||||
|
||||
exit 0;
|
Loading…
Reference in New Issue
Block a user