Glissiamo sul fatto che è da stamane che fa più caldo nel corridoio e nelle altre stanze che nella mia...
Ho finito di mettere a puntino lo script bash x tener d'occhio apcupsd e/o altri servizi vari, da infilare nel crontab. Il che, salvo altri imprevisti, dovrebbe farmi passare le ferie natalizie un tanticchia più tranquilla.
#!/bin/bash
ROOT_UID=0 # Only users with UID 0 have root privileges.
E_NOTROOT=67 # Non-root exit error.
LOGFILE=/var/log/wakeup.log
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ ! -d "$LOGFILE" ]
then
touch $LOGFILE
chmod 640 $LOGFILE
fi
# let's list all "files" opened by service $1
# then pipe all output to /dev/null:
/usr/sbin/lsof -c $1 > /dev/null 2>&1
# capture the return value and act accordingly:
if [ "$?" -eq 0 ]; then
echo "The processes related to $1 are running."
echo `date +'%b %e %H:%M:%S'`" -- Service $1 still active." >> $LOGFILE
exit 0
else # trying to re-start the missing service
echo "NO processes related to $1 found! Trying to restart it."
echo `date +'%b %e %H:%M:%S'`" -- Service $1 died between last check and this! Restarting it..." >> $LOGFILE
/sbin/service $1 start > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
echo "Service $1 restarted successfully."
echo `date +'%b %e %H:%M:%S'`" -- Service $1 restarted successfully" >> $LOGFILE
exit 0
else
echo "Uh-oh. Couldn't re-start service $1!"
echo `date +'%b %e %H:%M:%S'`" -- Unable to restart service $1. Sorry!!!" >> $LOGFILE
fi
fi
Naturalmente c'è chi l'avrebbe fatto con awk, chi con sed, chi andando a cercare il pidfile e fare un kill fittizio su tale pid. E visto che a me non andava ne' di confrontare quale di questi metodi fosse meno impegnativo per la CPU, ne' di riscrivere daccapo il coso, ringrazio e tiro avanti :-)
Ovviamente lo scriptillo gira ogni 10 minuti ininterrottamente, da venerdì ad oggi e (PER ORA) apcupsd ha smesso con le sue morti improvvise e silenti. Classico.
Sarebbe bello poter far altrettanto con il riscaldamento che non funge. Ovvero venerdì, quando sono andata via, fungeva. Quando sono arrivata stamattina, dopo essermi beatamente contemplata i vari segni della gelata tra Acilia e Roma, col menga che fungeva.
Nessun commento:
Posta un commento
NOTA BENE: TUTTI i commenti sono moderati... se non sono in vacanza, controllo quasi ogni giorno. Ovviamente, se siete spammers vi cancello :)