1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/bin/bash
- PATH="$PATH:/usr/local/sbin:/usr/sbin"
- udomain=`hostname -d`
- uhostname=`hostname`
- uFecha=`date +%b" "%_d" "%H:%M:%S`
- uNameService="freeradius"
- uSubject="subject: $uhostname $uNameService not running correctly?"
- uState="/tmp/$uNameService.down"
- uLog="/var/log/levanta_$uNameService"
- if [ ! -w $uLog ];
- then
- echo "WARNING: Archivo $uLog no existe. Creando..." ; touch $uLog;
- else
- if [ `du -k $uLog | cut -f 1` -gt 2000 ]; then echo "Archivo $uLog muy grande, vaciando" ; >$uLog; fi
- fi
- usendmail=$(which sendmail)
- if [ -z $usendmail ]; then echo "ERROR: Sendmail no detectado en el sistema. Sendmail instalado? Sendmail no detectado"; fi
- [ -r "$uState" ] && secondtime=$(cat $uState)
- greplines=`ps axc | awk '{print $NF}' | grep -c "$uNameService"`
- function show_status {
- echo "Number of proccess $uNameService=$greplines"
- }
- output="
- $uFecha: $uNameService RESTARTED:
- Log:
- $(show_status)
- $uNameService not running?. Restarting $uNameService."
- show_status
- if [ "$greplines" = 0 ]; then
- if [ "x$secondtime" == "x" ]
- then
- echo "$uNameService down!"
- echo "1" >$uState
- else
- echo $output >> $uLog
- #echo "$uSubject
- #$output
- #"| $usendmail -f root@$udomain soporte@cablenet.com.ar
- /etc/init.d/$uNameService restart || (/etc/init.d/$uNameService stop ; sleep 5 ; /etc/init.d/$uNameService start)
- echo "Restarting $uNameService!!!"
- fi
- else
- [ -r "$uState" ] && rm -f "$uState"
- echo "$uNameService OK"
- fi
|