I wrote a script to do this a while ago, but it is in bash:
Code:
#!/bin/ash
if test $# = 0
then
interface=eth0
elif test $# = 1
then
interface="$1"
else
echo "Usage: $(basename $0) [interface]"
exit 1
fi
# make sure the interface is sane
if ! ifconfig "$interface" grep 'RX packets' | awk '{ print $3 }' | grep '^[0-9]*$'
then
exit 1
fi
while :
do
oldvar="$(ifconfig "$interface" | grep 'RX packets' | awk '{ print $3 }')"
sleep 30
var="$(ifconfig "$interface" | grep 'RX packets' | awk '{ print $3 }')"
if test "$oldvar" = "$var"
then
shutdown -h now
exit 0
fi
done
exit 0
It checks received packets every 30 seconds, and if you haven't received any packets it shuts down. You can change the time if you need to.
I used this for regular downloads and only rarely torrents, but it should still work because it is monitoring received packets not sent packets.