To remedy this, don't force grep to output the linesmake sure that matches the patternscript does not generate output. You You can do this with the exec >/dev/null 2>&1. Also, we should be using grep with its -q option since we're not at all interested in seeing the output from it (this would generally also speed up the grep as it does not need to parse the whole file, but in this case it make very little difference in speed since the file is so small).
#!/bin/sh
# redirect all output not redirected elsewhere to /dev/null by default:
exec >/dev/null 2>&1
while true; do
date >sdown.txt
ping -c 1 -W 1 myserver.net >pingop.txt 2>&1
if ! grep -q "64 bytes" pingop.txt 2>/dev/null;txt; then
mutt -s "Server Down!" [email protected] <sdown.txt
break
fi
sleep 10
done
#!/bin/sh
exec >/dev/null 2>&1
while true; do
if ! ping -q -c 1 -W 1 myserver.net >/dev/null 2>&1;net; then
date | mutt -s "Server Down!" [email protected]
break
fi
sleep 10
done
#!/bin/sh
exec >/dev/null 2>&1
while ping -q -c 1 -W 1 myserver.net >/dev/null 2>&1;net; do
sleep 10
done
date | mutt -s "Server Down!" [email protected]
* * * * * ping -q -c 1 -W 1 >/dev/null 2>&1 || ( date | mail -s "Server down" [email protected] )