Showing posts with label shell scripts. Show all posts
Showing posts with label shell scripts. Show all posts

Thursday, August 20, 2009

Delete delete delete delete please delete please delete the word sed.

There are times when I just should use perl.

Monday, September 08, 2008

Minimal remote webserver test.

Using sh and telnet magic.

Workmate of mine had to resort to perl. I was sure it could be done with just a sh-script. I was right. What a beauty. Copy & Paste below or go to pastebin.

#!/bin/sh
timeout=10
tracefile=telnettrace
HOST=$1

telnet_commands() {
tout=${timeout}
echo open $1 80

sleep 1

while [ "$tout" -ge 0 ]
do
if tail -1 $tracefile 2>/dev/null | grep "character" > /dev/null
then
echo "HEAD / HTTP/1.0\n"
tout=-15
continue
else
sleep 1
tout=$[$tout-1]
fi
done
tout=${timeout}
while [ "$tout" -ge 0 ]
do
if tail -1 $tracefile 2>/dev/null | grep "^$" > /dev/null
then
tout=-15
continue
else
sleep 1
tout=$[$tout-1]
fi
done
}

telnet_commands $HOST | telnet |tee $tracefile