Respawn a crashed service

Nothing special... Part of crontab...

#!/bin/sh

SERVICE=$1

if ( ! ps -axe | grep $SERVICE > /dev/null ) ; then
	$SERVICE;
fi

System watch dog

The script is part of my crontab. It check every 10 min, for these services. If a service i failed (crashed), the script send a mail to selected persons...

#!/bin/sh

RCPT="nmmm@nmmm.nu"

#idea:
#HOST=`cat /etc/HOSTNAME`
HOST="FOO"

isOk(){
        if ( ps -axe | grep $1 > /dev/null ) ;  then
                printf "OK" ;
        else
                printf "FAIL" ;
        fi
}

lookup(){
        if [ `isOk $1` = "FAIL" ] ; then
                MSG="$HOST - $1 is down"
                echo $MSG | mail $RCPT -s "$MSG" ;
        fi
}

lookup httpd
lookup named
lookup inetd

WWW reminder

Every system administrator must take a look of some places on the web (like rootshell.com) every few time. But the most of sysops (like me) forgot to do this...

This script go to these pages, then send a mail with attachments... Put it in crontab...

#!/bin/sh

wwwreminder(){
	NAME=$1
	WHERE=$2

	lynx -source "$WHERE" | uuencode "$NAME".htm
}

RCPT="nmmm@nmmm.nu"

mail -s "www reminder" $RCPT << [DONE]

Hi my Master,
here you are the most important pages for you...

`wwwreminder "Postgres"  "www.postgresql.org"`
`wwwreminder "Rootshell" "www.rootshell.com/beta/news.html"`
`wwwreminder "mod-ssl"   "www.modssl.org"`
`wwwreminder "sendmail"  "www.sendmail.org"`

[DONE]

fromdos extention

exends fromdos command

#!/bin/sh

fromdos <$1> $1.fromdos
rm $1
mv $1.fromdos $1

Apache HTTPd log analizer/WWW counter

One of My first scripts. Before i made it we FTP the log file, then import it in MsAccess, then count it with SQL..

#!/bin/sh
printf "web site results:"
cat /var/lib/httpd/logs/access_log |\
	grep "GET $1" |\
	wc -l

..or new version

#!/bin/sh

LOG=/var/lib/httpd/logs/access_log

printf "web site results:"
cat $LOG | grep "GET $1" | wc -l

mpg123 extention

extention of popular console MP3 player. Dive into subdirs and play all *.mp3 files using mpg123

#!/bin/sh

Play(){
	while read FILE; do
		echo playing "$FILE"
		mpg123 "$FILE"
	done
}

Pass(){
	while read DIR; do
		cd "$DIR"
		pwd

		if [ $Racurs ]; then 
			if [ $Racurs = "-r" ]; then 
				ls -1p | grep "/" | Pass
			fi
		fi

		ls -1 *.mp3 2 > /dev/null | Play
		cd ..
	done
}

if [ ! $1 ]; then 
	cat << [END]

================
mpg123 extention
================
(c)opyleft 07.1999, Nikolay Mijaylov Mijaylov, nmmm@nmmm.nu
Copying:
	GPL !!!
Usage:
	mp3 dir [-r]
	Check whole directory for *.mp3, then play them

	dir	directory with *.mp3 files
	-r	perform recursive search
[END]

	exit
fi

Racurs=$2;
echo "$1" | Pass

Copyleft 16.Sep.1999,
Nikolay Mijaylov
nmmm@nmmm.nu
http://www.nmmm.nu/