[Eisfair] autohalt Probleme

Friedhold Schuster f.schuster at gmx.de
Mi Feb 15 18:11:35 CET 2017


Hallo Marcus,

Am 15.02.2017 um 16:51 schrieb Marcus Roeckrath:
> Bitte poste /usr/local/autohalt/autohalt.

Bitte:

#! /bin/sh
# set -xv  # Debughilfe
#----------------------------------------------------------------------------
# /sbin/autohalt - autohalt
#
# Creation   : 2009-01-03 christian
# Last update: $Id: autohalt 20 2009-01-03 11:52:27Z christian $
#
# Copyright (c) 2009 the Christian Richter, <richterch(at)gmx(dot)de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
----------------------------------------------------------------------------

#exec 2> `pwd`/autohalt-trace$$.log
#set -x

# set packages name
packageName=autohalt

# include configuration file
. /etc/config.d/autohalt

# include eislib
. /var/install/include/eislib

# set variable
down=0

. /var/install/include/check-eisfair-version
# Setup system specific values
case "${EISFAIR_SYSTEM}" in
     eisfair-1)  # eisfair-1 code
         fpingPath="/usr/local/bin"
     ;;
     *)  # code for other systems
         fpingPath="/usr/local/bin"
     ;;
esac
# 
----------------------------------------------------------------------------
# function check_process
# 
----------------------------------------------------------------------------
check_process()
{
if [ "${AUTOHALT_LOCK_PROCESS_N}" -ge 1 ]
then
     check="true"
     idx_1=1
     while [ "${idx_1}" -le "${AUTOHALT_LOCK_PROCESS_N}" ]
     do
         eval PROCESS='$AUTOHALT_LOCK_PROCESS_'${idx_1}
         if [ `ps -A | grep -c ${PROCESS}` -ge 1 ]
         then
             down=0
             clrhome
             message="...at least process ${PROCESS} is running, don't 
shutdown."
             mecho -warn "${message}"
             echo
             echo
             if [ "${AUTOHALT_LOG}" == "yes" ]
             then
                 echo "`date '+%b %d %X'`: ${message}" >> 
/var/log/autohalt.log
             fi
             exit 0
         else
             down=1
             message="...no specified process running"
         fi
         idx_1=`/usr/bin/expr ${idx_1} + 1`
     done
fi
}


# 
----------------------------------------------------------------------------
# function check_users
# 
----------------------------------------------------------------------------
check_users()
{
if [ "${AUTOHALT_CHECK_ALL_USERS}" == "yes" ]
then
     check="true"
     tmpfile=/tmp/autohalt_who.$$
     do_shutdown='yes'
     max_login_days="${AUTOHALT_MAX_LOGIN_DAYS}"
     max_login_time=`expr ${max_login_days} \* 24 \* 3600`
     if [ -z "`who`" ]
     then
         message="...no users are logged in"
         down=1 # shutdown kann ausgelöst werden
     else
         user_file="/etc/passwd"
         while read line
         do
             set -- ${line}
             USER=${line%%:*}
             if [ `who -q | grep -c ${USER}` -ge 1 ]
             then
                 down=0
                 who | grep ${USER} > ${tmpfile}
                 idx_2=1
                 while read line
                 do
                     param="\$$idx_2"
                     login_time=`echo "${line}" | awk '{print $3" "$4" 
"$5}'`
                     login_time=`date -d "${login_time}" +%s`
                     now=`date +'%b %e %H:%M'`
                     now=`date -d "${now}" +%s`
                     diff=`expr ${now} - ${login_time}`
                     if [ "${diff}" -lt "${max_login_time}" ]
                     then
                         do_shutdown='no'
                         clrhome
                         message="...at least user ${USER} is online, 
don't shutdown."
                         mecho -warn "${message}"
                         echo
                         echo
                         if [ "${AUTOHALT_LOG}" = "yes" ]
                         then
                             echo "`date '+%b %d %X'`: ${message}" >> 
/var/log/autohalt.log
                         fi
                         rm -f ${tmpfile}
                         exit 0
                     fi
                     idx_2=`expr ${idx_2} + 1`
                 done < ${tmpfile}
             fi
         done < $user_file
     fi
     if [ "${do_shutdown}" == "yes" ]
     then
         message="...no users are logged in"
         down=1
     fi
     rm -f ${tmpfile}
fi
}


# 
----------------------------------------------------------------------------
# function check_singe_user
# 
----------------------------------------------------------------------------
check_single_user()
{
if [ "${AUTOHALT_CHECK_SINGLE_USER_N}" -ge 1 ]
then
     max_login_days="${AUTOHALT_MAX_LOGIN_DAYS}"
     max_login_time=`expr ${max_login_days} \* 24 \* 3600`
     tmpfile=/tmp/autohalt_who_single.$$
     check="true"
     idx_3=1
     while [ "${idx_3}" -le "${AUTOHALT_CHECK_SINGLE_USER_N}" ]
     do
         eval USER='$AUTOHALT_CHECK_SINGLE_USER_'${idx_3}
         if `who -q | grep -c ${USER}` -ge 1
         then
             down=0
             who | grep ${USER} > ${tmpfile}
             while read line
             do
                 login_time=`echo "${line}" | awk '{print $3" "$4" "$5}'`
                 login_time=`date -d "${login_time}" +%s`
                 now=`date +'%b %e %H:%M'`
                 now=`date -d "${now}" +%s`
                 diff=`expr ${now} - ${login_time}`
                 if [ "${diff}" -lt "${max_login_time}" ]
                 then
                     do_shutdown='no'
                     clrhome
                     message="...at least user ${USER} is online, don't 
shutdown"
                     mecho -warn "${message}"
                     echo
                     echo
                     if [ "${AUTOHALT_LOG}" = "yes" ]
                     then
                         echo "`date '+%b %d %X'`: ${message}" >> 
/var/log/autohalt.log
                     fi
                     rm -f ${tmpfile}
                     exit 0
                 fi
             done < ${tmpfile}
         else
             down=1
             message="...no users are logged in"
         fi
         idx_3=`/usr/bin/expr ${idx_3} + 1`
     done
     rm -f ${tmpfile}
fi
}


# 
----------------------------------------------------------------------------
# function check_range
# 
----------------------------------------------------------------------------
check_range()
{
if [ "${AUTOHALT_IP_RANGE_N}" -ge 1 ]
then
     check="true"
     idx_4=1
     while [ "${idx_4}" -le "${AUTOHALT_IP_RANGE_N}" ]
     do
         eval range='$AUTOHALT_IP_RANGE_'$idx_4
         IP=`${fpingPath}/fping -r 1 -a -q -g ${range}`
         if [ "${IP}" != "" ]
         then
             down=0
             clrhome
             message="...at least one client is on, dont't shutdown"
             mecho -warn "${message}"
             echo
             echo
             if [ "${AUTOHALT_LOG}" = "yes" ]
             then
                 echo "`date '+%b %d %X'`: ${message}" >> 
/var/log/autohalt.log
             fi
             exit 0
         else
             down=1
             message="...all clients offline"
         fi
         idx_4=`/usr/bin/expr ${idx_4} + 1`
     done
fi
}


# 
----------------------------------------------------------------------------
# function check_unique_ip
# 
----------------------------------------------------------------------------
check_unique_IP()
{
if [ "${AUTOHALT_IP_N}" -ge 1 ]
then
     check="true"
     idx_5=1
     while [ "${idx_5}" -le "${AUTOHALT_IP_N}" ];do
         eval unique='$AUTOHALT_IP_'$idx_5
         IP=`${fpingPath}/fping -r 1 -q -u ${unique}`
         if [ "${IP}" == "" ]
         then
             down=0
             clrhome
             message="...at least one client is on, dont't shutdown"
             mecho -warn "${message}"
             echo
             echo
             if [ "${AUTOHALT_LOG}" == "yes" ]
             then
                 echo "`date '+%b %d %X'`: ${message}" >> 
/var/log/autohalt.log
             fi
             exit 0
         else
             down=1
             message="...all clients offline"
         fi
         idx_5=`/usr/bin/expr ${idx_5} + 1`
     done
fi
}

commands()
{
     rm -f /tmp/autohalt_exec.sh
     idx=1
     while [ "${idx}" -le "${AUTOHALT_EXEC_N}" ]
     do
         eval pre_exec='$AUTOHALT_EXEC_'$idx
         echo ${pre_exec} >> /tmp/autohalt_exec.sh
         idx=`/usr/bin/expr ${idx} + 1`
     done
     /bin/sh /tmp/autohalt_exec.sh

}


# 
----------------------------------------------------------------------------
# MAIN
# 
----------------------------------------------------------------------------
idx=0
echo "please wait a moment..."
if [ "${AUTOHALT_NO_RESPONSE}" == "" ]
then
     AUTOHALT_NO_RESPONSE=0
fi
while [ "${idx}" -lt "${AUTOHALT_TRIALS}" ]
do
     if [ "${AUTOHALT_CHECK_PROCESS}" == "yes" ]
     then
         check_process
     fi
     if [ "${AUTOHALT_CHECK_USERS}" == "yes" ]
     then
         if [ "${AUTOHALT_CHECK_ALL_USERS}" == "yes" ]
         then
             check_users
         fi
         check_single_user
     fi
     if [ "${AUTOHALT_CHECK_IP}" == "yes" ]
     then
         check_range
         check_unique_IP
     fi
     if [ "${check}" == "true" ]
     then
         if [ "${down}" == 1 ]
         then
             if [ "${idx}" -lt "${AUTOHALT_TRIALS}" ] && [ 
"${AUTOHALT_NO_RESPONSE}" -ge 1 ]
             then
                 SLEEP=`/usr/bin/expr ${AUTOHALT_NO_RESPONSE} \/ 
${AUTOHALT_TRIALS}`
                 echo -n "${message}, but i wait ${SLEEP} seconds and 
try it again `/usr/bin/expr ${AUTOHALT_TRIALS} \- ${idx}`"
                 if `/usr/bin/expr ${AUTOHALT_TRIALS} \- ${idx}` -eq 1
                 then
                     echo " time..."
                 else
                     echo " times..."
                 fi
                 sleep "${SLEEP}"s
             fi
         fi
     else
         clrhome
         echo "Oops, nothing to do."
         echo "Please check Configuration."
         echo
         echo
         exit 0
     fi
     idx=`/usr/bin/expr ${idx} + 1`
done
if [ "${down}" == 1 ]
then
     clrhome
     echo "${message}, ready to shutdown."
     echo
     if [ "${AUTOHALT_LOG}" == "yes" ]
     then
         if [ "${AUTOHALT_EXEC}" == "yes" ]
         then
             echo "`date '+%b %d %X'`: ${message}." >> /var/log/autohalt.log
             echo "`date '+%b %d %X'`: Script starting..." >> 
/var/log/autohalt.log
             echo "Script(s) will be started..."
             commands
             echo "... done."
             echo "`date '+%b %d %X'`: ...done, ready to shutdown." >> 
/var/log/autohalt.log
         else
             echo "`date '+%b %d %X'`: ${message}, ready to shutdown." 
 >> /var/log/autohalt.log
         fi
     else
         if [ "${AUTOHALT_EXEC}" == "yes" ]
         then
             echo "Script(s) will be started..."
             commands
             echo "... done."
         fi
     fi
     echo
     if [ "${AUTOHALT_DO_DEBUG}" != "yes" ]
     then
         /sbin/shutdown -h now
     fi
fi
# 
----------------------------------------------------------------------------
# END
# 
----------------------------------------------------------------------------
exit 0


Mehr Informationen über die Mailingliste Eisfair