#!/bin/bash end_it_all () { echo echo "did some funny things some $COUNT times... naughty, naughty" exit } trap end_it_all HUP QUIT INT TERM COUNT=0 HOST=localhost while ((1)) ; do wget -r -l100 -U "Stop sending me SPAM! This is the only way to make you undestand." "http://$HOST" && end_it_all ((COUNT++)) done