#!/bin/sh # Shutdown des Systems, wenn niemand angemeldet... # /etc/crontab: */15 * * * * root /scripts/auto-shutdown.sh echo "Green-IT Auto-Shutdown" # Pruefe Uptime des Systems.. upSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')" upMins=$((${upSeconds} / 60)) [ "${upMins}" -lt "30" ] && echo " Systemuptime unter 30 Minuten! Abruch." && exit 0 echo " Online Users:" LOGINS=`lsof |awk '{if ($3 !~ /^root$|^USER$|^avahi$|^ntp$|^daemon$|^statd$|^haldaemon$|^messagebus$|^nobody$|^postfix$|^www-data$/) print $3}'|sort |uniq` echo " `who -s`" echo " $LOGINS" RUSER=`who -u` if [ -z "$RUSER" ] ; then # Logins LOGINS=`lsof |awk '{if ($3 !~ /^root$|^USER$|^avahi$|^ntp$|^daemon$|^statd$|^haldaemon$|^messagebus$|^nobody$|^postfix$|^www-data$/) print $3}'|sort |uniq |wc -l` if [ $LOGINS = "0" ] ; then touch /users-offline echo " $LOGINS Benutzer angemeldet, PowerOFF." #sendemail -f `hostname`@domain.net -t myuser@domain.net -u PowerOFF -m "Keine Benutzer angemeldet, PowerOFF" -s mail.domain.net poweroff fi else touch /users-online fi exit 0