t="$(mktemp -t bitcoin)"
That doesn't work so well -- no XXX's in the mktemp -t template.
And I think you really do want the trap - otherwise your /tmp directory
will get filled up with these dang files.
Yes -- newlines separating each piped command are better (though
I prefer to indent all but the first one) -- I was being lazy and just
typing as I do at the command prompt.
Yes -- mktemp or the more recent tempfile are probably better.
I was just being lazy again, and doing it as I have done it for 30
years, long before those commands existed. Sorry. The main
problem with my old fashioned method, and even with mktemp,
is a security issue -- a hacker can get you to write a file that
they have setup, via a symlink that you thought was your file.
The main problem with mktemp and tempfile is that not all
systems have them (though you have to be on a fairly old,
odd, or barebones system not to have them.)
You can find more discussion of the temp file issue at:
http://www.linuxsecurity.com/content/view/115462/151/ Safely Creating Temporary Files in Shell Scripts
So ... all this suggests the following:
#!/bin/sh
# Display foreign IP addresses coming from port 8333 --or-- connected to local port 8333.
# Append line at end with date and count of addresses displayed.
t="$(tempfile -p bitcoin)"
trap 'rm -f $t; trap 0; exit' 0 1 2 3 15
netstat -an |
awk '$6 == "ESTABLISHED" && /:8333/ { split($5, a, ":"); print a[1]}' |
tee "$t"
echo "# $(date) $(wc -l < $t) Bitcoin clients seen."