#! /bin/sh -e # wwwoffle-swat -- list and interrupt fetching of individual files # Copyright : http://www.fsf.org/copyleft/gpl.html # Author : Dan Jacobson -- http://jidanni.org/comp/wwwoffle/ # Created On : June 2003 # Last Modified On: Sat Feb 6 02:18:04 2010 # Update Count : 149 # need root. Tested on uncompressed cache only case $1 in --help|-\?)exec cat<<\EOF During a wwwoffle fetch run, I noticed I was fetching some giant file, eating up my precious bandwidth, and needed a handy way to stop it, without stopping all of wwwoffle. Run this program (no args) and it will print current downloads. Using arg -k will ask you which to kill. Of course if you are still in the browser that requested the file, you can probably just hit "stop", and don't need to use this script. Also helpful: alias content-length='wget -Y off --spider -t 1' #URL EOF esac test -w ${wwwoffle_cache:=/var/cache/wwwoffle}|| { echo $0: not enough permissions, try again as e.g. root 1>&2; exit 44;} cd $wwwoffle_cache/lasttime; ask=0 case "$1" in --big) find -name D\* -size +${2?}c -exec fuser -v {} \; -exec ls -og {} \; 2>&1|sed /^$/d exit;; -t) #unlisted option, for me testing when offline e=($(ls D*)); sleep 120 4<${e?} 5<${e[1]?} 6<${e[2]?}& trap "kill $! 2>&-" 0;; -k)ask=1;; -a)#kill all downloads fuser -k -HUP * 2>&-; exit;; #2>&- needed now, 12/05 '');; *)echo $0: $*: \? try --help 1>&2; exit 33;; esac set -- $(ls -S D*) #by size test $# -eq 0 && { echo $0: $PWD empty 1>&2; exit 54;} #set -- $(fuser $@ 2>&1|cut -d: -f 1) #2>&1 for "POSIX fuser" set -- $(fuser $@ 2>&1|perl -nwe 's/:.+//&&print') #psmisc 21.8-1!! #didn't check other uses of fuser in this script though test $# -eq 0 && { echo $0: no downloads in progress\? 1>&2; exit 55;} sizes=(dummy $(find $@ -printf %s\ )) names=(dummy $(sed : ${@/D/U})) #adds newlines c=0; for i; do echo $((++c)) ${sizes[$c]}\ ${names[$c]};done expr $ask >/dev/null while read -p 'Interrupt # ' v do case "$v" in "")break;; *[^0-9]*)echo $0: invalid choice 1>&2; exit 37;; esac fuser -kiv -HUP ${!v?bad choice} #when bad, trap is missed though done #But why sometimes a jpg is slowly filling my browser, but fuser etc. says #there is no such open file...