Hallo,
ich benutze schon sehr lange das Auto Off-Skript aus der Wiki. Dort ist eine Fuktion logit(). Diese speichert die Logeinträge aber in die Datei /var/log/syslog.
Ich bin immer noch am rätseln wie ich die Einträge in eine separate Datei schreiben kann. Das Skript sieht wie folgt aus:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | #!/bin/bash # #set -x . /etc/autoshutdown.conf logit() { logger -p local0.notice -s -- AutoShutdown: $* } IsOnline() { for i in $*; do ping $i -c1 if [ "$?" == "0" ]; then logit PC $i is still active, auto shutdown terminated return 1 fi done return 0 } IsRunning() { for i in $*; do if [ `pgrep -c $i` -gt 0 ] ; then logit $i still active, auto shutdown terminated return 1 fi done return 0 } IsDamonActive() { for i in $*; do if [ `pgrep -c $i` -gt 1 ] ; then logit $i still active, auto shutdown terminated return 1 fi done return 0 } IsPortInUse() { for i in $*; do LANG=C netstat -an | grep -q "${myIp}:${i}.*ESTABLISHED$" Err=${?} if [ ${Err} -eq 0 ] ; then logit "Port ${i} is still in use, auto shutdown terminated" return 1 fi done return 0 } IsBusy() { # Samba if [ "x$SAMBANETWORK" != "x" ]; then if [ `/usr/bin/smbstatus -b | grep $SAMBANETWORK | wc -l ` != "0" ]; then logit samba connected, auto shutdown terminated return 1 fi fi #damons that always have one process running IsDamonActive $DAMONS if [ "$?" == "1" ]; then return 1 fi #backuppc, wget, wsus, .... IsRunning $APPLICATIONS if [ "$?" == "1" ]; then return 1 fi # check network-ports if [ "x${NETWORKPORTS}" != "x" ]; then myIp=$(LANG=C /sbin/ifconfig | sed -n "/inet addr/ { s|^[a-z ]*:\([0-9\.]*\).*$|\1|p }" | head -n 1) IsPortInUse ${NETWORKPORTS} if [ "$?" == "1" ]; then return 1 fi fi # Read logged users USERCOUNT=`who | wc -l`; # No Shutdown if there are any users logged in test $USERCOUNT -gt 0 && { logit some users still connected, auto shutdown terminated; return 1; } IsOnline $CLIENTS if [ "$?" == "1" ]; then return 1 fi return 0 } COUNTFILE="/var/spool/shutdown_counter" OFFFILE="/var/spool/shutdown_off" # turns off the auto shutdown if [ -e $OFFFILE ]; then logit auto shutdown is turned off by existents of $OFFFILE exit 0 fi if [ "$AUTO_SHUTDOWN" = "true" ] || [ "$AUTO_SHUTDOWN" = "yes" ] ; then IsBusy if [ "$?" == "0" ]; then # was it not busy already last time? Then shutdown. if [ -e $COUNTFILE ]; then # shutdown rm -f $COUNTFILE logit auto shutdown caused by cron /sbin/halt -p exit 0 else # shut down next time touch $COUNTFILE logit marked for shutdown in next try exit 0 fi else rm -f $COUNTFILE #logit aborted exit 0 fi fi logit malfunction exit 1 |
Gruß
Zcelo12