#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) echo version = 1.02 of nowcheck 2010 Feb 26 # 2010 Feb 26, 1.02: cleanup # 2010 Feb 26, 1.01: no maximum! # 2008 Oct 6, 1.00: origin # Dr. Thomas D. Schneider, Ph.D. # National Institutes of Health # schneidt@mail.nih.gov # toms@alum.mit.edu (permanent) # http://alum.mit.edu/www/toms (permanent) if ($#argv == 0) then echo "usage: nowcheck [-a] [-k] [-m #] [-d #]" echo "Check that nowhere links work from your ~/now directory." echo "-a flag shows all pointers (otherwise only missing ones shown)" echo "-k flag removes links that do not have a directory" echo "-m 5 flag sets the maximum links to report to 5" echo "-d 8 delete the 8th link in the current numbering" echo "See the nowhere script." echo endif # default parameters: @ max = 5000000 # maximum links to report set all = 0 # show all set kill = 0 # kill links with no target set allspacer = '' # space to add if showing existing links too set delete = 0 # the number of a link to delete #echo "number of arguments = $#argv" set n = 1 # argument number while ($n <= $#argv) # echo "argument ${n}: $argv[$n]" if ("$argv[$n]" == '-m') then @ next = $n + 1 if ($next > $#argv) then echo 'missing argument for -m' else set max = $argv[$next] echo "maximum links to report is set to $max" @ n = $n + 1 endif endif if ("$argv[$n]" == '-a') then set allspacer = ' ' # space to add if showing existing links too set all = 1 endif if ("$argv[$n]" == '-k') then set kill = 1 endif if ("$argv[$n]" == '-d') then endif if ("$argv[$n]" == '-d') then @ next = $n + 1 if ($next > $#argv) then echo 'missing argument for -d' else set delete = $argv[$next] echo "deleting link $delete" @ n = $n + 1 endif endif @ n = $n + 1 end cd ~/now set here = `pwd` @ counter = 0 foreach link (`ls`) # ls -l $link set location = `ls -l $link|tr ' ' '\n'|tail -1` set pointer = `ls -l $link|tr ' ' '\n'|tail -3` # echo $location if (-d $location) then if ($all) then @ counter = $counter + 1 echo "$counter exists:" $pointer endif else @ counter = $counter + 1 echo "$counter gone:${allspacer}" $pointer if ($kill == 1) then set name = `echo $pointer | tr ' ' '\n'|head -1` echo " rm -f $name" endif if ($delete == $counter) then set name = `echo $pointer | tr ' ' '\n'|head -1` echo " rm -f $name" rm -f $name endif endif if ($counter >= $max) then exit endif end