karl@cs.duke.edu (Karl Ramm) (08/28/88)
Posting-number: Volume 4, Issue 41 Submitted-by: "Karl Ramm" <karl@cs.duke.edu> Archive-name: blachman/Part2 From: Nancy Blachman <decvax!decwrl!sun!idi!resonex!nancy@Ucb-Vax.ARPA> To: net.unix,net.unix-wizards,net.sources Subject: Actual Tricks, shells, csh aliases and the like, 2 of 3 Date: 16 Oct 84 21:22:55 GMT Organization: Resonex Inc., Sunnyvale, CA > [Know anybody with a GREAT .login or .cshrc?] > I'm interested in collecting the little tricks, shell scripts, awk > hacks, csh aliases, and such that people have built to make their daily > life a little easier or more automatic. Being a fairly new system > administrator I don't have the big toolbox that years of messing around > will leave you with. If you have any hacks you're proud of (or that > you aren't proud of, but which work anyway), and you're willing to make > them public, mail them to me. I'll collect, collate, shuffle, sort, > munge, judge, select and discard them and then "summarize to the net". This article focuses shell scripts I received in response to my solicitation. The first article of this series concentrates on aliases, and .cshrc and .login files. The third article centers on C programs and awk scripts. /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/ > Nancy Blachman {allegra,hplabs,ihnp4,sun}!resonex!nancy (408)720 8600 x37 < /\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\//\/ :::::::::::::: shells/1 :::::::::::::: Date: Thu, 13 Sep 84 12:49:57 edt From: allegra!vax135!cornell!tesla!mac (Michael Mc Namara) To: cornell!vax135!houxm!mhuxl!ulysses!allegra!resonex!nancy Subject: Cute cshell - sh scripts If your are like most UNIX systems, you have a plethora of different terminals that your system is supposed to support. Sure, with termcap and terminfo, and programs written to use them, the interface gets easier. If you only ever login to one particular terminal, you can set term = "vt131" or TERM=vt131 export TERM in your .login or .profile. But what if you, or some of your users, drift around using different terminal types-- You have a terminal room with many different terminals. Here is a set of shell scripts & C programs that use the "echo terminal type" command that many terminals support, to do automatic terminal type identification and setting: (of course I've only made it work for the terminals we have here at Cornell, and some day I should write more of it in C...) This one is written for cshell: ########################################## # Identify and set terminal type (csh)# ########################################## set noglob echo Please wait... stty cbreak -echo # this sequence will cause all terminals we have to echo something # except for adm's; those users are told to hit 'a' when they see # please wait echo ' CZ[c' sleep 1 # this calls a c program to grab the id string from the terminal # program is included later... set type = `/usr/new/rin.login` stty -cbreak echo new crt ######################### # the or in the vt100 terminal type is because vt100's respond # to both ^[Z and ^[[c, but DEC threatens to eliminate one of # the responces (I forget which).. The extra stty back you see # with DG terminals (Data General) is because their backspace is # ^Y instead of ^H ( Home on DG terminals) This involves a modification # of stty, which you would care about only if you have them--Write to me. ################## if ( $type == "[?1;0c" || $type == "[?1;0c[?1;0c" ) then set term = vt100 echo "VT101" else if ( $type == "[?1;2c" || $type == "[?1;2c[?1;2c" ) then set term = vt100 echo "VT100" else if ( $type == "[?1;11c[?1;11c") then set term = ct500 echo "[7mCIT - 500[m" else if ( $type == "[?12;5;0;102c" ) then set term = vt100 echo "VT125" else if ($type == "[?1;2c[?1;2c") then set term = vt100 echo "VT100, with Selenar Graphics" else if ( $type == "o#\!R" ) then set term = dg200 stty stop undef start undef back echo "DDG200E" else if ( $type == "o#'C3" ) then set term = dg450 stty back echo "FS11BFS00 DATA GENERAL DASHER D450" else if ( $type == "o#'K3" ) then set term = dg450 stty back echo "FS11BFS00 DATA GENERAL DASHER D450" else if ( $type == "/K" ) then set term = vt52 echo "Visual 50" else if ( $type =~ "\\4*" ) then set term = hp2621 echo HP2621 else if ( $type =~ "a" ) then set term = adm3a echo "adm3a" else if ($type == "50" ) then set term = w50 echo "WYSE50" else # Ask user for terminal type -- for some reason the above didn't work set no_name_yet=1 set no_name_yet = 1; while( $no_name_yet ) echo -n "Please enter terminal type (hit return for menu) " set ttyname = ($< ); switch( $ttyname ) case d450: case dg450: set term=dg450; stty back set no_name_yet = 0; breaksw; case vt100: set term=vt100; set no_name_yet = 0; breaksw; case v50: case vt52: set term=vt52; set no_name_yet = 0; breaksw; case hp2621: case hp: set term=hp2621; set no_name_yet = 0; breaksw; case wyse50: set term=w100; set no_name_yet = 0; breaksw; case adm5: set term=adm5; set no_name_yet = 0; breaksw; case adm3+: case adm3: case adm3a: set term=adm3+; set no_name_yet = 0; case d200: case dg200: set term=dg200; stty stop undef start undef back ; set no_name_yet = 0; breaksw; case other: echo -n "Enter terminal name: " set term=($< ); set no_name_yet = 0; breaksw; case '': echo Terminal abbreviations are: echo "Dasher 450 : dg450" echo "Dasher 200 : dg200" echo "Visual 50 : v50" echo "VT100 : vt100" echo "HP 2621 : hp2621" echo "ADM5 : adm5" echo "ADM3+ : adm3+" echo "Use 'other' to specify terminals not on this menu" breaksw; default: echo "I didn't understand that. Hit return for a menu." endsw end unset no_name_yet unset ttyname endif stty -cbreak stty echo unset noglob Ok, This one is used for Bourne shell lovers: (I used /bin/test because one user had an executable file called test somewhere in his path ahead of where this program lived...That one took days to track down...) echo "Please Wait..." stty start stop crt new back -echo cbreak echo ' CZ[c' sleep 1 TYPE=`/usr/new/rin.login` stty echo -cbreak if ( /bin/test \( $TYPE = "[?1;0c" \) -o \( $TYPE = "[?1;0c[?1;0c" \) ) then TERM=vt100 echo "[7mVT101[m" elif ( /bin/test \( $TYPE = "[?1;2c" \) -o \( $TYPE = "[?1;2c[?1;2c" \) ) then TERM=vt100 echo "#3[7mVT100[m" echo "#4?[7mVT100[m" elif ( /bin/test $TYPE = "[?1;11c[?1;11c") then TERM=ct500 echo "CT 500" elif ( /bin/test $TYPE = "o#!R" ) then TERM=dg200 stty stop undef stty start undef stty crt stty back echo "D DATA GENERAL DASHER D200E" elif ( /bin/test $TYPE = "o#'C3" ) then TERM=dg450 stty crt stty back echo "FS11BFS00 DATA GENERAL DASHER D450" elif ( /bin/test $TYPE = "/K" ) then TERM=vt52 echo "UVisual 50T" elif ( /bin/test $TYPE = "50" ) then TERM=w50 clear echo "WYSE 50" elif ( /bin/test $TYPE = "\4088000" ) then TERM=hp2621 echo HP2621 elif ( /bin/test $TYPE = "a" ) then TERM=adm3a echo ADM3a else stty start stty stop stty new crt set no_name_yet=1 echo while ($no_name_yet) do { echo echo Which terminal do you have? echo Hit return for a menu. read INP case $INP in 100 | v | vt100) { TERM=vt100 break } ;; adm5) { TERM=adm5 break } ;; adm3+) { TERM=adm3+ break } ;; 450 | dg450 | d450) { TERM=dg450 stty back break } ;; 200 | dg200 | d200) { TERM=dg200 stty stop undef stty start undef stty back break } ;; 50 | vt52 | v50) { TERM=vt52 break } ;; 2621 | hp2621 | hp) { TERM=hp2621 break } ;; other) { echo -n Enter terminal name: read tname TERM=$tname break } ;; ''|?|help) { echo Terminal abbreviations are: echo echo Dasher 450: dg450 echo Dasher 200: dg200 echo Visual 50: vt52 echo VT100 : vt100 echo HP 2621 : hp2621 echo ADM3+ : adm3+ echo ADM5 : adm5 echo "Use 'other' to specify other terminals." echo } ;; * ) { echo "I did not understand that." } ;; esac } done fi export TERM ********* And here is the c program that read's in the terminal ID string: /* rin -- read in a char string which may not be terminated */ char buf[256]; int n; main () { n = read(0,buf,256); write(1,buf,n); printf("\n"); } *************** Use them, abuse them. Of course you have to paw through your terminal manuanls to discover what (if any) string they respond to, and test for the response accordingly... ---MAC :::::::::::::: shells/2 :::::::::::::: From: hplabs!azure!billp To: tektronix!hplabs!resonex!nancy Date: Thursday, 13 Sep 84 09:23:49 PDT Subject: Re: Tricks, shell and awk scripts, csh aliases and the like Here are some that I like and use a lot. 'del' and 'undelete' are just two links to the same file. This way if somebody copies one, they get the other too ------------------------------------------------------------------------------- :::::::::::::: : mv :::::::::::::: : 'prompts if the destination file already exists' /bin/mv -i $* ------------------------------------------------------------------------------- :::::::::::::: : cp :::::::::::::: : 'prompts if the destination file already exists' /bin/cp -i $* ------------------------------------------------------------------------------- :::::::::::::: : del, undelete :::::::::::::: : '"del" throws files into the waste basket' : 'files preceded by "," are automagically removed after 7 days' : '"undelete" pulls files out of the waste basket' : 'if invoked without an argument, both commands list the contents of the' : 'waste basket.' case $0 in *del) if test -z "$1" then ls -lus $HOME/.waste_basket else for i do echo -n "deleting " tmp=`basename $i` /bin/mv -i $i $HOME/.waste_basket/,$tmp echo $i done fi;; *undelete) if test -z "$1" then ls -lus $HOME/.waste_basket else for i do echo -n "recovering " tmp=`basename $i` /bin/mv -i $HOME/.waste_basket/,$tmp $i echo $i done fi;; esac ------------------------------------------------------------------------------- :::::::::::::: : vi :::::::::::::: : 'backs up file(s) before editing them' : 'files preceded by "," are automagically removed after 7 days' for i do if test -f $i then echo -n "backing up " tmp=`basename $i` /bin/cp -i $i $HOME/.vi_backup/,$tmp echo $i fi done /usr/ucb/vi $* ------------------------------------------------------------------------------- Bill Pfeifer {ucbvax,decvax,ihnp4,allegra,uw-beaver,hplabs} !tektronix!tekmdp!billp :::::::::::::: shells/3 :::::::::::::: Date: Thu, 13 Sep 84 13:58:09 pdt From: turtlevax!ken (Ken Turkowski) To: resonex!nancy Subject: Re: Tricks, shell and awk scripts, csh aliases and the like You asked for it, you've got it! Here's ALL of my personal nifties: Ken ************************************************** echo x - bin mkdir bin echo x - bin/CC cat >bin/CC <<'!Funky!Stuff!' # set outname=a.out foreach file ($argv) if ("$file" =~ *.[cso]) then set outname=$file:r break endif end echo cc -o $outname $* exec cc -o $outname $* !Funky!Stuff! echo x - bin/appt cat >bin/appt <<'!Funky!Stuff!' # set notetype=$0 set notetype=$notetype:t set notefile=~/.$notetype # if ($notetype == appt) then # set notetype=appointment # set notefile=~/calendar # endif if ($#argv == 0) then test -t 0 && echo Please enter your $notetype entry '(^D to end):' echo ' ' >> $notefile exec cat >> $notefile endif switch ($1) case -: exec vi $notefile case -rm: cat /dev/null > $notefile exec echo The ${notetype}s are removed. case -what: exec cat $notefile default: echo '' >> $notefile echo "$*" >> $notefile endsw !Funky!Stuff! echo x - bin/asfix cat >bin/asfix <<'!Funky!Stuff!' case $# in 0) file=/tmp/afix$$ trap "cat $file; rm $file; exit" 0 trap "rm $file; exit" 3 9 cat > $file ;; 1) file=$1 ;; *) echo Usage `basename $0` ' [ <file> ]' ;; esac ed - $file << EOF v/[:\.]/s/^/ / g/:./s/:/: / wq EOF !Funky!Stuff! echo x - bin/atcat cat >bin/atcat <<'!Funky!Stuff!' # if ($#argv < 2) then set cmd=$0 echo Usage: "$cmd:t <time> <word> [ <word> ... ]" exit endif set atcmd="echo $argv[2-] > `tty`" at $1 << EOF $atcmd EOF !Funky!Stuff! echo x - bin/atecho cat >bin/atecho <<'!Funky!Stuff!' # if ($#argv < 2) then set cmd=$0 echo Usage: "$cmd:t <time> <word> [ <word> ... ]" exit endif set atcmd="echo $argv[2-] > `tty`" at $1 << EOF $atcmd EOF !Funky!Stuff! echo x - bin/beautify cat >bin/beautify <<'!Funky!Stuff!' # set TMP=/tmp/cb$$ foreach file (argv) echo Beautifying $file: cb < $file > $TMP cat $TMP > $file end rm $TMP !Funky!Stuff! echo x - bin/blankclean cat >bin/blankclean <<'!Funky!Stuff!' sed -e 's/^ $//' -e 's/ *$//' $* !Funky!Stuff! echo x - bin/bphone cat >bin/bphone <<'!Funky!Stuff!' phonefile=$HOME/.`basename $0`s echo ' ' case $# in 0) ed - $phonefile << EOF g/./s/$/\\ / g/ /s//\\ /g g/;/s// /g 1,\$p q EOF exit ;; esac case $1 in -) chmod 644 $phonefile vi $phonefile chmod 444 $phonefile exit ;; esac trap "rm /tmp/data$$; exit" 0 2 for name do grep -y "$name" $phonefile >> /tmp/data$$ done ed - /tmp/data$$ << EOF g/./s/$/\\ / g/ /s//\\ /g g/;/s// /g 1,\$p q EOF !Funky!Stuff! echo x - bin/catalog cat >bin/catalog <<'!Funky!Stuff!' # catalog - produce complete file structure list from directory # # Parameters: 1: directory name (optional) # 2: indentation string (empty on first call) # # Produces on standard output the file structure emanating from # the current directory. Each descent into a subdirectory # is indicated by further indentation. Directories are indicated # by surrounding [], and executable files are prefaced with a *. # if ( $#argv == 0) then echo "file structure from directory `pwd`" date echo '' else cd $1 endif foreach i ( * ) if ( -d $i ) then echo "${2}[ $i ]" $0 $i "$2 . " endif if ( "$i" != '*' ) then if ( -x $i ) then echo "${2} *$i " else echo "${2} $i " endif endif endif end !Funky!Stuff! echo x - bin/circum cat >bin/circum <<'!Funky!Stuff!' there=$1 shift otherstuff="$*" back=`whoami` last=`hostname` IFS=' ! ' for link in $there do back="$last!$back" last=$link done IFS=' ' echo mail $there!$back (date; echo "$otherstuff") | mail -s "Circumlocution to $last" $there!$back !Funky!Stuff! echo x - bin/comfmt cat >bin/comfmt <<'!Funky!Stuff!' exec fmt | \ sed -e '1s/^\([ ]*\)/\1\/\* /' -e '2,$s/^\([ ]*\)/\1 \* /' -e '${P s/\*.*/*\// }' !Funky!Stuff! echo x - bin/comstrip cat >bin/comstrip <<'!Funky!Stuff!' exec sed -e 's/\/\*//' -e 's/\*\///' -e 's/^[ ]*\** *//' !Funky!Stuff! echo x - bin/decvert cat >bin/decvert <<'!Funky!Stuff!' # if ($#argv == 0) then set args=`cat` if ($#args != 0) $0 $args exit endif foreach hexnum ($argv) dc << EOF 16i ${hexnum}p EOF end !Funky!Stuff! echo x - bin/f77 cat >bin/f77 <<'!Funky!Stuff!' PATH=/usr/bin SPECLIB=/usr/ken/cmd/lib/libc.a exec f77 "$@" $SPECLIB !Funky!Stuff! echo x - bin/famove cat >bin/famove <<'!Funky!Stuff!' # if ($#argv != 2) then echo Usage: $0 '<source family root> <destination family root>' exit endif foreach file ($1.*) set suffix=`expr $file : "$1\.\(.*\)"` echo mv $file $2.$suffix mv $file $2.$suffix end if (-e $1) then echo mv $1 $2 mv $1 $2 endif !Funky!Stuff! echo x - bin/gredit cat >bin/gredit <<'!Funky!Stuff!' # set CAESAR=/mnt/cad/bin/caesar set SEARCHPATH=(-p ::/usr/ken/caesar/symlib) set COLORMAP=(-c mumap.cmap) set GRTERM=ttyh7 set caesarfile=() foreach parm ($argv) if ($?flag) then switch ($flag) case g: set GRTERM=$parm breaksw case p: set SEARCHPATH=(-p "$parm") breaksw case R: set SEARCHPATH=($SEARCHPATH:$parm) breaksw case c: set COLORMAP=(-c $parm) breaksw endsw unset flag continue endif if ($parm =~ -*) then switch ($parm) case -g: set flag=g continue case -p: set flag=p continue case -P: set SEARCHPATH=() continue case -R: set flag=R continue case -C: set COLORMAP=() continue case -c: set flag=c continue endsw else set caesarfile=($caesarfile $parm) endif end onintr - $CAESAR -g $GRTERM $SEARCHPATH $COLORMAP $caesarfile !Funky!Stuff! echo x - bin/grindall cat >bin/grindall <<'!Funky!Stuff!' # set flags= set fileargs= onintr cleanup foreach file ($argv) if ($file =~ -*) then if ($file == -t) then set stdout else set flags=($flags $file) endif else set fileargs=($fileargs $file) endif end if ($?stdout) then foreach file ($fileargs) vgrind -t $flags $file end else foreach file ($fileargs) vgrind -t $flags $file >> /usr/tmp/grind$$ end vpr -T $fileargs[1] -t /usr/tmp/grind$$ endif cleanup: rm /usr/tmp/grind$$ !Funky!Stuff! echo x - bin/hardasm cat >bin/hardasm <<'!Funky!Stuff!' # grasm -1 -l -x $* |& pr -f -h "grasm -l -x $*" | vpr -l !Funky!Stuff! echo x - bin/hexvert cat >bin/hexvert <<'!Funky!Stuff!' # if ($#argv == 0) then set args=`cat` if ($#args != 0) $0 $args exit endif foreach decnum ($argv) dc << EOF 16o ${decnum}p EOF end !Funky!Stuff! echo x - bin/job cat >bin/job <<'!Funky!Stuff!' PATH=/usr/ken/cmd/bin:/usr/ucb:/bin:/usr/bin case $# in 0) exec echo Usage: `basename $0` '-;' or $0 '<job description>' ;; esac case $1 in -) exec ex $HOME/.joblog ;; -h | -hr | -hrs) shift hrs=$1 shift exec echo ' job:' $hrs hours # $* >> $HOME/.joblog ;; -tail) exec tail -22 $HOME/.joblog ;; -today) { while read line do case $line in *login*) login="$line" ;; esac done echo -n "$login" "for " diffdate "$login" "`date`" } < $HOME/.joblog ;; -login) echo ' login:' "`date`" >> $HOME/.joblog ;; -summary) cat $HOME/.joblog | while read line do case $line in *login*) login="$line" ;; *logout*) logout="$line" echo -n "$login" "for " diffdate "$login" "$logout" esac done ;; *) exec echo ' job:' "`date`" # $* >> $HOME/.joblog ;; esac !Funky!Stuff! echo x - bin/ledger cat >bin/ledger <<'!Funky!Stuff!' # set notetype=$0 set notetype=$notetype:t set notefile=~/.$notetype # if ($notetype == appt) then # set notetype=appointment # set notefile=~/calendar # endif if ($#argv == 0) then test -t 0 && echo Please enter your $notetype entry '(^D to end):' echo ' ' >> $notefile exec cat >> $notefile endif switch ($1) case -: exec vi $notefile case -rm: cat /dev/null > $notefile exec echo The ${notetype}s are removed. case -what: exec cat $notefile default: echo '' >> $notefile echo "$*" >> $notefile endsw !Funky!Stuff! echo x - bin/lstree cat >bin/lstree <<'!Funky!Stuff!' # if ($#argv == 0) then set root=. else set root=($*) endif exec find $root -print | sort | sed -e 's/[^ \/]*\// /g' !Funky!Stuff! echo x - bin/match cat >bin/match <<'!Funky!Stuff!' cat $2 | while read x do for word in $x do case $word in $1) echo $word ;; esac done done !Funky!Stuff! echo x - bin/narrow cat >bin/narrow <<'!Funky!Stuff!' echo \! !Funky!Stuff! echo x - bin/outmesg cat >bin/outmesg <<'!Funky!Stuff!' # set notetype=$0 set notetype=$notetype:t set notefile=~/.$notetype # if ($notetype == appt) then # set notetype=appointment # set notefile=~/calendar # endif if ($#argv == 0) then test -t 0 && echo Please enter your $notetype entry '(^D to end):' echo ' ' >> $notefile exec cat >> $notefile endif switch ($1) case -: exec vi $notefile case -rm: cat /dev/null > $notefile exec echo The ${notetype}s are removed. case -what: exec cat $notefile default: echo '' >> $notefile echo "$*" >> $notefile endsw !Funky!Stuff! echo x - bin/path cat >bin/path <<'!Funky!Stuff!' IFS="${IFS}:" for cmddir in $PATH do test -s $cmddir/$1 && echo " $cmddir/$1" done !Funky!Stuff! echo x - bin/pphone cat >bin/pphone <<'!Funky!Stuff!' phonefile=$HOME/.`basename $0`s echo ' ' case $# in 0) ed - $phonefile << EOF g/./s/$/\\ / g/ /s//\\ /g g/;/s// /g 1,\$p q EOF exit ;; esac case $1 in -) chmod 644 $phonefile vi $phonefile chmod 444 $phonefile exit ;; esac trap "rm /tmp/data$$; exit" 0 2 for name do grep -y "$name" $phonefile >> /tmp/data$$ done ed - /tmp/data$$ << EOF g/./s/$/\\ / g/ /s//\\ /g g/;/s// /g 1,\$p q EOF !Funky!Stuff! echo x - bin/progression cat >bin/progression <<'!Funky!Stuff!' last= for backup in $1_?? do case $last in "") last=$backup continue; esac echo '' echo From $last to $backup: diff $last $backup last=$backup done echo '' echo From $last to $1: diff $last $1 !Funky!Stuff! echo x - bin/query cat >bin/query <<'!Funky!Stuff!' # set notetype=$0 set notetype=$notetype:t set notefile=~/.$notetype # if ($notetype == appt) then # set notetype=appointment # set notefile=~/calendar # endif if ($#argv == 0) then test -t 0 && echo Please enter your $notetype entry '(^D to end):' echo ' ' >> $notefile exec cat >> $notefile endif switch ($1) case -: exec vi $notefile case -rm: cat /dev/null > $notefile exec echo The ${notetype}s are removed. case -what: exec cat $notefile default: echo '' >> $notefile echo "$*" >> $notefile endsw !Funky!Stuff! echo x - bin/releave cat >bin/releave <<'!Funky!Stuff!' # set tty=`tty` set tty=`expr $tty : '.*tty\(.*\)'` set leaveproc=`ps gt$tty | grep -w leave` kill -9 $leaveproc[1] date leave $* !Funky!Stuff! echo x - bin/reminder cat >bin/reminder <<'!Funky!Stuff!' # set notetype=$0 set notetype=$notetype:t set notefile=~/.$notetype # if ($notetype == appt) then # set notetype=appointment # set notefile=~/calendar # endif if ($#argv == 0) then test -t 0 && echo Please enter your $notetype entry '(^D to end):' echo ' ' >> $notefile exec cat >> $notefile endif switch ($1) case -: exec vi $notefile case -rm: cat /dev/null > $notefile exec echo The ${notetype}s are removed. case -what: exec cat $notefile default: echo '' >> $notefile echo "$*" >> $notefile endsw !Funky!Stuff! echo x - bin/reremind cat >bin/reremind <<'!Funky!Stuff!' # set tty=`tty` set tty=`expr $tty : '.*tty\(.*\)'` set leaveproc=`ps gt$tty | awk '$5 ~ /^remind$/ { print $1 }'` if ($#leaveproc > 1) echo $#leaveproc reminds were running kill -9 $leaveproc date if ($#argv <= 1) then remind $* else set time=$1 shift remind $time "$*" endif !Funky!Stuff! echo x - bin/restore cat >bin/restore <<'!Funky!Stuff!' # Truncate filename if necessary set file=$1 if (`expr $file:t : '.*'` >= 11) then set savename=`expr $file : '\(.*\)'$file:t` set savename=$savename`expr $file:t : '\(...........\)'` else set savename=$file endif switch ($#argv) case 1: set nonomatch set backup=(${savename}_[0-9][0-9]) if ("$backup" == "${savename}_[0-9][0-9]") then echo Error: No backups found for $file exit endif set backup=$backup[$#backup] echo No backup number specified. Using latest: $backup breaksw case 2: set backup=${savename}_$2 breaksw default: exec echo Usage: `basename $0` '<file>' '[<backup number>]' endsw if ( { cp $backup $file } ) then echo $file restored from $backup. echo -n Do you wish to keep "$backup? " set response=$< if ($response !~ y*) then rm $backup endif endif !Funky!Stuff! echo x - bin/rot13 cat >bin/rot13 <<'!Funky!Stuff!' tr "A-Za-z" "N-ZA-Mn-za-m" !Funky!Stuff! echo x - bin/shufcol cat >bin/shufcol <<'!Funky!Stuff!' trap 'rm /tmp/$$.*; exit' 0 2 cat > /tmp/$$.0 i=1 for cols do cut -f$cols < /tmp/$$.0 > /tmp/$$.$i filelist="$filelist /tmp/$$.$i" i=`expr $i + 1` done paste $filelist !Funky!Stuff! echo x - bin/signature cat >bin/signature <<'!Funky!Stuff!' PATH=/bin:/usr/bin cat echo -- cat $HOME/.signature !Funky!Stuff! echo x - bin/swab cat >bin/swab <<'!Funky!Stuff!' # if ($#argv == 0) then dd conv=swab else onintr cleanup foreach file ($argv) cp $file /tmp/swab$$ dd if=/tmp/swab$$ of=$file conv=swab end cleanup: rm /tmp/swab$$ endif !Funky!Stuff! echo x - bin/what cat >bin/what <<'!Funky!Stuff!' cat $HOME/.query echo -n 'save? (n or d to delete, e to edit) ' read response case $response in n | no | d | delete) rm $HOME/.query && echo The query is removed. ;; "" | y | yes | s | save) exit ;; e | edit) exec vi $HOME/.query < /dev/tty exit ;; *) echo Bad response: "$response" exec $0 ;; esac !Funky!Stuff! echo x - bin/whereis cat >bin/whereis <<'!Funky!Stuff!' N=$# command=echo case "$1" in -*) command=`expr "$1" : '-\(.*\)'` shift N=`expr $N - 1` ;; esac case $N in 0) exec echo Usage: `basename $0` [ -command ] pattern file ... ;; 1) files=`fgrep -l "$1" *` ;; *) files=`fgrep -l "$@"` ;; esac case $files in "") echo $1 not found in any files. exit ;; esac exec $command $files !Funky!Stuff! echo x - bin/wide cat >bin/wide <<'!Funky!Stuff!' echo \" !Funky!Stuff! echo x - bin/xprint cat >bin/xprint <<'!Funky!Stuff!' case $# in 1) eval $1 | eval pr -f -h \"$1\" | vpr -l ;; *) command='cat $file' for file do case $file in -*) command=`expr "$file" : '-\(.*\)'` case $command in *\$file*) ;; *) command="$command \$file" ;; esac ;; *) eval $command | eval pr -f -h \"$command\" | vpr -l ;; esac done esac !Funky!Stuff! echo x - bin/archives mkdir bin/archives echo x - bin/archives/newsweed cat >bin/archives/newsweed <<'!Funky!Stuff!' # cd if ($#argv == 0) then if (-e .newsweed) then set WEEDGROUPS=`cat .newsweed` else set WEEDGROUPS= endif else set WEEDGROUPS=$* endif if ($#WEEDGROUPS == 0) then onintr echo Searching for articles in all newsgroups readnews -l | \ grep Subject | \ sed -e 's/Subject: *//' -e 's/^[rR][eE]:* *//' | \ sort -u > /tmp/weed$$a if (-z /tmp/weed$$a) then echo No news. else cp /tmp/weed$$a /tmp/weed$$b echo Please remove article titles which you do not wish to read sleep 1 onintr - vi /tmp/weed$$b onintr cleanup comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c echo Removing unwanted articles newsec -f /tmp/weed$$c endif else foreach group ($WEEDGROUPS) echo Searching for articles in group\(s\): echo $group readnews -l -n $group | \ grep Subject | \ sed -e 's/Subject: *//' -e 's/^[rR]e:* *//' | \ sort -u > /tmp/weed$$a if (-z /tmp/weed$$a) then echo in newsgroups $group. else cp /tmp/weed$$a /tmp/weed$$b echo Please remove article titles which you do not wish to read sleep 1 onintr - vi /tmp/weed$$b onintr cleanup comm -23 /tmp/weed$$a /tmp/weed$$b > /tmp/weed$$c echo Removing unwanted articles newsec -f /tmp/weed$$c endif end endif cleanup: rm /tmp/weed$$? !Funky!Stuff! echo x - bin/archives/pk_01 cat >bin/archives/pk_01 <<'!Funky!Stuff!' : Roff, nroff, or eqn input text for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "sed 's/^x//' >$file <<'!Funky!Stuff!'" sed 's/^/x/' $file; echo "!Funky!Stuff!" done : Text files for file in `file $* | sed -n -e '/commands text$/s/:[^:]*$//p' -e '/ascii text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "cat >$file <<'!Funky!Stuff!'" cat $file; echo "!Funky!Stuff!" done : Directories, recursively for dir in `file $* | sed -n '/directory$/s/:.*//p'` do echo "echo x - $dir" echo "mkdir $dir" file=`echo $dir/*` test "$file" != "$dir/*" && $0 $file done !Funky!Stuff! echo x - bin/archives/pkf cat >bin/archives/pkf <<'!Funky!Stuff!' for dir do echo "echo x - $dir" echo "mkdir $dir"; for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "cat >$file <<'!Funky!Stuff!'" cat $file; echo "!Funky!Stuff!" done $0 `file $dir/* | sed -n '/directory$/s/:.*//p'` done !Funky!Stuff! echo x - bin/archives/pkg cat >bin/archives/pkg <<'!Funky!Stuff!' for file do echo "echo x - $file" echo "cat >$file <<'!Funky!Stuff!'" cat $file; echo "!Funky!Stuff!" done !Funky!Stuff! echo x - bin/archives/pkn cat >bin/archives/pkn <<'!Funky!Stuff!' for dir do echo "echo x - $dir" echo "mkdir $dir"; for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "sed 's/^x//' >$file <<'!Funky!Stuff!'" sed 's/^/x/' $file; echo "!Funky!Stuff!" done $0 `file $dir/* | sed -n '/directory$/s/:.*//p'` done !Funky!Stuff! echo x - bin/archives/prod cat >bin/archives/prod <<'!Funky!Stuff!' # set flags=() set syslist=() foreach arg ($argv) switch ($arg) case -s*: if (`expr $arg : '.*'` > 9) then rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.......\)'` else rm -f /usr/spool/uucp/STST.`expr $arg : '-s\(.*\)'` endif set syslist=($syslist $arg) breaksw case -*: set flags=($flags $arg) breaksw default: if (`expr $arg : '.*'` > 7) then rm -f /usr/spool/uucp/STST.`expr $arg : '\(.......\)'` else rm -f /usr/spool/uucp/STST.$arg endif set syslist=($syslist -s$arg) breaksw endsw end foreach sys ($syslist) /usr/lib/uucp/uucico -r1 $flags $sys end !Funky!Stuff! echo x - bin/bourne_scripts mkdir bin/bourne_scripts echo x - bin/bourne_scripts/lookdoc sed 's/^x//' >bin/bourne_scripts/lookdoc <<'!Funky!Stuff!' xtrap exit 2 xcase $# in x 0) x ul | more x exit ;; xesac xfor names xdo x case $names in x -n) x default=n ;; x -t) x default=t ;; x -m*) x macros="$macros $names" ;; x *.n | *.nr) x nroff $macros $names | ul | more ;; x *.t | *.tbl) x soelim $names | tbl | nroff $macros - | ul | more ;; x *) x case $default in x n) x nroff $macros $names | ul | more ;; x t) x soelim $names | tbl | nroff $macros - | ul | more ;; x "") x ul $names | more ;; x esac x esac xdone !Funky!Stuff! echo x - bin/bourne_scripts/CC cat >bin/bourne_scripts/CC <<'!Funky!Stuff!' outname=a.out for argv do case $argv in *.[cos]) outname=`expr $argv : '\(.*\)\.'` break ;; esac done cc -o $outname $* !Funky!Stuff! echo x - bin/bourne_scripts/appt cat >bin/bourne_scripts/appt <<'!Funky!Stuff!' case $0 in appt) notetype=appointment notefile=$HOME/calendar ;; *) notetype=$0 notefile=$HOME/.$0 ;; esac case $# in 0) test -t 0 && echo Please enter your $notetype '(^D to end):' echo '' >> $notefile exec cat >> $notefile ;; esac case $1 in -) exec vi $notefile ;; -rm) cat /dev/null > $notefile exec echo The ${notetype}s are removed. ;; -what) exec cat $notefile ;; *) echo '' >> $notefile exec echo "$*" >> $notefile ;; esac !Funky!Stuff! echo x - bin/bourne_scripts/beautify cat >bin/bourne_scripts/beautify <<'!Funky!Stuff!' for files do echo $files: cb < $files > /tmp/cb$$ cat /tmp/cb$$ > $files done rm /tmp/cb$$ !Funky!Stuff! echo x - bin/bourne_scripts/format cat >bin/bourne_scripts/format <<'!Funky!Stuff!' case $# in 0) echo "Usage: `basename $0` [-flags] <filename> [ <filename> ... ]" exit 1 ;; esac for names do case $names in -*) flags="$flags $names" ;; *.t) outfile=`expr $names : '\(.*\)\.'`.d soelim $names | tbl | nroff $flags - > $outfile ;; *.tbl) outfile=`expr $names : '\(.*\)\.'`.doc soelim $names | tbl | nroff $flags - > $outfile ;; *.n) outfile=`expr $names : '\(.*\)\.'`.d nroff $flags $names > $outfile ;; *.nr) outfile=`expr $names : '\(.*\)\.'`.doc nroff $flags $names > $outfile ;; *) echo Don\'t know what to do with $names ;; esac done !Funky!Stuff! echo x - bin/bourne_scripts/print cat >bin/bourne_scripts/print <<'!Funky!Stuff!' PATH=/avsd/ava/turk/bin:/usr/local/bin:/usr/bin indent=0 for names do case $names in -i) indent=1 ;; *) args="$args $names" ;; esac done case $indent in 0) pr $args | lpr ;; *) pr $args | indent | lpr ;; esac !Funky!Stuff! echo x - bin/bourne_scripts/repeat cat >bin/bourne_scripts/repeat <<'!Funky!Stuff!' case $1 in -[0-9]*) number=`expr $1 : '-\(.*\)'` shift while test $number -gt 0 do eval $* number=`expr $number - 1` done exit ;; *) echo Executing forever: $* 1>&2 number=0 trap 'echo Executed $number times.; exit' 2 while true do eval $* number=`expr $number + 1` done ;; esac !Funky!Stuff! echo x - bin/bourne_scripts/restore cat >bin/bourne_scripts/restore <<'!Funky!Stuff!' case $# in 2) ;; *) exec echo Usage: `basename $0` '<file>' '<version>' ;; esac : Truncate filename if necessary if test `expr $1 : '.*'` -gt 11 then savename=`expr $1 : '\(...........\)'` else savename=$1 fi savename=${savename}_$2 cp $savename $1 && rm $savename && echo $1 restored from $savename !Funky!Stuff! echo x - bin/bourne_scripts/save cat >bin/bourne_scripts/save <<'!Funky!Stuff!' for file do if test `expr $file : '.*'` -gt 11 then savename=`expr $file : '\(...........\)'` else savename=$file fi for copy in ${savename}_?? do latest=$copy done if test $latest = "${savename}_??" then latest=${savename}_01 else latest=`expr $latest : '.*_\([0123456789]*\)$' + 1` case $latest in ?) latest=0$latest ;; esac latest=${savename}_$latest fi cp $file $latest && echo $file saved as $latest done !Funky!Stuff! echo x - bin/csh_scripts mkdir bin/csh_scripts echo x - bin/csh_scripts/newsweed cat >bin/csh_scripts/newsweed <<'!Funky!Stuff!' # set TEMP=/tmp/weed$$ set NEWSRC=~/.newsrc set AWKFILE=/usr/ken/cmd/lib/newsweed.awk onintr echo Searching for articles in all newsgroups readnews -l $* | sort -o ${TEMP}a if (-z ${TEMP}a) then echo No news. else cp ${TEMP}a ${TEMP}b echo Please remove article titles which you do not wish to read sleep 1 onintr - vi ${TEMP}b onintr cleanup if ( { cmp -s ${TEMP}a ${TEMP}b } ) then echo No articles deleted. else comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c echo Removing unwanted articles cp $NEWSRC $NEWSRC.old awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d cp ${TEMP}d $NEWSRC endif endif cleanup: rm ${TEMP}? !Funky!Stuff! echo x - bin/csh_scripts/pathname cat >bin/csh_scripts/pathname <<'!Funky!Stuff!' # foreach cmddir ($path) if ( -e $cmddir/$1 ) echo " $cmddir/$1" end !Funky!Stuff! echo x - bin/local mkdir bin/local echo x - bin/local/format cat >bin/local/format <<'!Funky!Stuff!' # if ($#argv == 0) then set progname=$0 set progname=$progname:t echo 'Usage:' $progname '[-v] [-n] [-print] [-troffflags] <filename> [ <filename> ... ]' exit (1) endif set flags set formatter="vtroff -t" set eqnsetter=eqn set docsuf=v set longdocsuf=vpr set more=0 foreach name ($argv) if ($more > 0) then set flags="$flags $name" @ more-- continue endif switch ($name) case -*: switch ($name) case -print: set print continue case -v: set formatter="vtroff -t" set eqnsetter=eqn set docsuf=v set longdocsuf=vpr continue case -n: set formatter=nroff set eqnsetter=neqn set docsuf=d set longdocsuf=doc continue case -[F123]: set more=1 default: set flags="$flags $name" endsw continue case *.et: set outfile=$name:r.$docsuf eval soelim $name | tbl | $eqnsetter | $formatter $flags > $outfile breaksw case *.t: set outfile=$name:r.$docsuf eval soelim $name | tbl | $formatter $flags > $outfile breaksw case *.tbl: set outfile=$name:r.$longdocsuf eval soelim $name | tbl | $formatter $flags > $outfile breaksw case *.e: set outfile=$name:r.$docsuf eval $eqnsetter $name | $formatter $flags > $outfile breaksw case *.eqn: set outfile=$name:r.$longdocsuf eval $eqnsetter $name | $formatter $flags > $outfile breaksw case *.n: set outfile=$name:r.$docsuf eval $formatter $flags $name > $outfile breaksw case *.nr: set outfile=$name:r.$longdocsuf eval $formatter $flags $name > $outfile breaksw default: echo Don\'t know what to do with $name continue endsw if ($?print) then if ("$formatter" == nroff) then vpr $outfile else vpr -t $outfile endif endif end !Funky!Stuff! echo x - bin/local/lntree cat >bin/local/lntree <<'!Funky!Stuff!' PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin if test $1 = -v then verbose=1 shift else verbose=0 fi case $2 in /*) target=$2 ;; *) target=`pwd`/$2 ;; esac if test -f $2 then echo Error: $2 is not a directory exit 1 fi cd $1 source=`pwd` if test `expr $target : $source/` != 0 then echo Error: $2 may be a subdirectory of $1 echo Try using the full path name of $2 \(no ..\'s\) exit 1 fi if test $verbose = 1 then set -x fi files=`type -f` case $files in "") ;; *) ln $files $target ;; esac for directory in `find '' -type d -a -print` do mkdir $target$directory cd $source$directory files=`type -f` case $files in "") ;; *) ln $files $target$directory ;; esac done !Funky!Stuff! echo x - bin/local/lookdoc cat >bin/local/lookdoc <<'!Funky!Stuff!' # if ($#argv == 0) then more exit endif set macros pipespec args foreach name ($argv) switch ($name) case -n: set pipespec=n breaksw case -t: set pipespec=t breaksw case -m*: set macros="$macros $name" breaksw case *.n: case *.nr: if ($pipespec != t) set pipespec=n set args="$args $name" breaksw case *.t: case *.tbl: set pipespec=t set args="$args $name" breaksw default: set args="$args $name" endsw end switch ($pipespec) case n: nroff $macros $args | more breaksw case t: soelim $args | tbl | nroff $macros - | col | more breaksw default: more $name breaksw endsw !Funky!Stuff! echo x - bin/local/newsweed cat >bin/local/newsweed <<'!Funky!Stuff!' TEMP=/tmp/weed$$ NEWSRC=$HOME/.newsrc AWKFILE=/usr/local/lib/newsweed.awk trap 'rm ${TEMP}?; exit' 0 2 echo Making list of article titles readnews -l $* | sort -o ${TEMP}a if test -s ${TEMP}a then cp ${TEMP}a ${TEMP}b echo Please remove article titles which you do not wish to read sleep 1 reset # So that vi's CRLF doesn't get trashed by another vi ${EDITOR-vi} ${TEMP}b if cmp -s ${TEMP}a ${TEMP}b then echo No articles deleted. else comm -23 ${TEMP}a ${TEMP}b | sed 's/ .*//' > ${TEMP}c echo Removing unwanted articles cp $NEWSRC $NEWSRC.old awk -f $AWKFILE $NEWSRC.old ${TEMP}c > ${TEMP}d cp ${TEMP}d $NEWSRC fi else echo No news. fi !Funky!Stuff! echo x - bin/local/nmail cat >bin/local/nmail <<'!Funky!Stuff!' #/bin/csh set found = 0 set arg = 1 while($arg <= $#argv) if(`echo $argv[$arg] | grep \!` != "") then set tuple = `echo $argv[$arg] | sed s/\\!/\ /` set upath = `uupath $tuple[1]` set found = $status set argv[$arg] = "$upath\!$tuple[2]" else set found = 0 endif if($found != 0) then set argv[$arg] endif @ arg = $arg + 1 end echo "mail $argv" mail $argv !Funky!Stuff! echo x - bin/local/peopledata cat >bin/local/peopledata <<'!Funky!Stuff!' peoplefile=$HOME/.peopledata echo ' ' case $# in 0) ed - $peoplefile << EOF g/./s/$/\\ / g/ /s//\\ /g 1,\$p q EOF exit ;; esac case $1 in -) chmod 600 $peoplefile vi $peoplefile chmod 400 $peoplefile exit ;; esac trap "rm /tmp/data$$; exit" 0 2 for name do grep -y "$name" $peoplefile >> /tmp/data$$ done ed - /tmp/data$$ << EOF g/./s/$/\\ / g/ /s//\\ /g 1,\$p q EOF !Funky!Stuff! echo x - bin/local/phone cat >bin/local/phone <<'!Funky!Stuff!' peoplefile=$HOME/.peopledata case $# in 0) ed - $peoplefile << EOF v/-/d g/./s/\([^ ]*\)[^-]* \(.*-.*\)/\1 \2/ 1,\$p EOF exit ;; esac case $1 in -) chmod 600 $peoplefile vi $peoplefile chmod 400 $peoplefile exit ;; esac trap "rm /tmp/data$$; exit" 0 2 for name do grep -y "$name" $peoplefile >> /tmp/data$$ done ed - /tmp/data$$ << EOF g/./s/\([^ ]*\)[^-]* \(.*-.*\)/\1 \2/ 1,\$p q EOF !Funky!Stuff! echo x - bin/local/pk cat >bin/local/pk <<'!Funky!Stuff!' for dir do echo "mkdir $dir"; for file in `file $dir/* | sed -n '/text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "cat >$file <<'#EOF#'" cat $file; echo "#EOF#" done pk `file $dir/* | sed -n '/directory$/s/:.*//p'` done !Funky!Stuff! echo x - bin/local/save cat >bin/local/save <<'!Funky!Stuff!' # if ("$1" =~ -*) then set suffix=`expr $1 : '-\(.*\)'` shift foreach file ($argv) if (`expr $file:t : '.*'` >= 11) then set savename=`expr $file : '\(.*\)'$file:t` set savename=$savename`expr $file:t : '\(...........\)'` else set savename=$file endif cp $file ${savename}_$suffix && \ echo $file saved as ${savename}_$suffix end exit endif foreach file ($argv) if (`expr $file:t : '.*'` >= 11) then set savename=`expr $file : '\(.*\)'$file:t` set savename=$savename`expr $file:t : '\(...........\)'` else set savename=$file endif set nonomatch set latest=(${savename}_[0-9][0-9]) if ("$latest" == "${savename}_[0-9][0-9]") then set latest=${savename}_01 else set latest=$latest[$#latest] set latest=`expr $latest : '.*_\([0123456789]*\)$' + 1` if ($latest < 10) set latest=0$latest set latest=${savename}_$latest endif cp $file $latest && echo $file saved as $latest end !Funky!Stuff! echo x - bin/local/shar cat >bin/local/shar <<'!Funky!Stuff!' : Roff, nroff, or eqn input text for file in `file $* | sed -n '/eqn input text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "sed 's/^x//' >$file <<'!Funky!Stuff!'" sed 's/^/x/' $file; echo "!Funky!Stuff!" done : Text files for file in `file $* | sed -n -e '/eqn input text$/d' -e '/text$/s/:[^:]*$//p'` do echo "echo x - $file" echo "cat >$file <<'!Funky!Stuff!'" cat $file; echo "!Funky!Stuff!" done : Directories, recursively for dir in `file $* | sed -n '/directory$/s/:.*//p'` do echo "echo x - $dir" echo "mkdir $dir" file=`echo $dir/*` test "$file" != "$dir/*" && $0 $file done !Funky!Stuff! echo x - bin/local/uuhosts cat >bin/local/uuhosts <<'!Funky!Stuff!' #!/bin/sh # '@(#) uuhosts.sh 1.22 84/08/07' # PATH will have to be adjusted for non-BSD systems. PATH=/usr/local/bin:/usr/ucb:/bin:/usr/bin LIB=/usr/lib # Routing information produced by pathalias. paths=$LIB/nmail.paths # The directory $NEWSMAP should contain the USENET news map information # from newsgroup net.news.map that is posted about once a month from # cbosgd!map, extracted by a line like this in $LIB/news/sys: # # newsmap:net.news.map:B:/usr/local/uuhosts -x # # Locally-known information should go in $LIB/news/net.news.map/Local. # The directory $MAILMAP is extracted by the same command from the # UUCP mail information posted to the same newsgroup. NEWSMAP=$LIB/news/net.news.map MAILMAP=$LIB/news/net.mail.map cd $NEWSMAP case $1 in -x) # extract a new map piece into the map directory temphead=/tmp/maphead.$$ temptext=/tmp/maptext.$$ awk ' BEGIN { temphead = "'$temphead'"; isnewsmap = 0; ismailmap = 0; shead = 0; stext = 1; snews = 2; smail = 3; scat = 4; scatting = 5; state = shead; print "Reply-To: news" >> temphead; } state == shead && /^From: / { print "Original-" $0 >> temphead; } state == shead && /^Subject: / { if ($2 != "Re:") for (x = 2; x <= NF; x++) { if ($x == "UUCPmap" || $x == "uucpmap" || $x == "UUCPMAP") { ismailmap = 1; break; } if ($x == "map" || $x == "Map" || $x == "MAP") { if (x <= 2) continue; x--; if ($x == "USENET") { isnewsmap = 1; break; } if ($x == "UUCP") { ismailmap = 1; break; } x++; } } if (!isnewsmap && !ismailmap) { print "Subject: not a map update" >> temphead; print "Original-" $0 >> temphead; } else print $0 >> temphead; } state == shead && /^$/ { if (isnewsmap != 0) state = snews; else if (ismailmap != 0) { state = scat; } else state = stext; next; } state == scat { if ($1 != "cat") state = scatting; else state = smail; } state == scatting { if ($1 == ":") state = smail; else print; } state == smail { print | "uuhosts -u"; } state == snews { print | "/bin/sh"; } state == stext { print; } ' > $temptext 2>&1 cat $temphead $temptext | /bin/mail news rm -f $temphead $temptext exit 0 ;; -u) # extract a UUCP map piece cd $MAILMAP /bin/sh for f in *map*.a *map*.ar do ar xv $f rm $f done ;; -g) # by geographical region shift if test $# -eq 0 then exec ls exit 1 fi exec cat $* exit 1 ;; -k) # by keyword shift exec awk ' BEGIN { inside = 1; outside = 0; state = outside; } /^Name:/ { state = inside; count = 0; useit = 0; } state == inside { block[count++] = $0; } /'"$*"'/ { useit = 1; } /^$/ && state == inside { if (useit == 1) { for (i = 0; i < count; i++) { print block[i]; } } state = outside; } ' * exit 1 ;; -*) # unknown option ;; "") # no arguments ;; *) # by site name for arg in $* do echo 'UUCP mail path:' grep '^'${arg} $paths echo ' UUCP mail host information:' cat $MAILMAP/${arg}* | tr % '\012' echo ' USENET news host information:' sed -n -e "/^Name:[ ]*${arg}/,/^$/p" * done exit 0 ;; esac echo 'Usage: 'uuhosts' hostname ... for information about a particular UUCP or USENET host or hosts, or 'uuhosts' -g geographical-region for information about USENET news sites in a geographical region, or 'uuhosts' -g for a list of known USENET geographical-regions. ' exit 1 !Funky!Stuff! :::::::::::::: shells/4 :::::::::::::: Date: Fri, 14 Sep 84 15:06:07 pdt From: hplabs!sdcrdcf!sdcsvax!celerity!barto (David Barto) To: sdcsvax!sdcrdcf!hplabs!resonex!nancy Subject: Re: Tricks, shell and awk scripts, csh aliases and the like Hi Nancy, I too am a 'new' system admin, and belive me, it won't take you too long to get quite a bag of tricks put together. Most of mine relate to source programs put together in shell scripts to keep track of things. I have 1 for news (at the end of the article) which keeps the active list up to date. Another nice program is one I call '#'. It is owned by root and setuid/setgid to root/daemon. I use it to 'become' root while doing 1 command # mv file1 file2 which requires root permission. It checks to see the normal userid is 'me' and then allows the command. I will send it along if you want it. I have shell scripts for doing things such as 'rootedit' a file. This is an alias for "alias re '# vi -v \!*'" I too would love to see the things you get back from the net. As well I have a sendmail config setup for making your configuration a breeze. If you want it I can send it under seperate cover. barto (david barto) Tele : (619) 271 9940 uucp : {decvax || ucbvax || ihnp4}!sdcsvax!celerity!barto uucp : akgua!celerity!barto arpa : sdcsvax!celerity!barto@NOSC : This is a shar archive. Extract with sh, not csh. echo x - Mkactive cat > Mkactive << '!Funky!Stuff!' #!/bin/sh # see Update.active for this usage # sed -e '1,/---/d'\ -e '1,/---/d'\ -e 's/^[ ]//'\ -e 's/ \(.*\)//'\ active.current | sort | sed -e '1,/Newsgroup/d' > current sed -e 's/ \(.*\)//' /usr/new/lib/news/active | sort > active diff active current > /tmp/active.diff echo "# active newsgroups not in local active file:" fgrep ">" /tmp/active.diff echo "# defunct newsgroups still in active file (also local groups):" fgrep "<" /tmp/active.diff /bin/rm current active /tmp/active.diff !Funky!Stuff! echo x - Mkdead cat > Mkdead << '!Funky!Stuff!' #!/bin/sh # see Update.active for usage # change all groups that we have (but shouldn't) to be removed, # and change all groups that we dont have (but sould) to be a comment sed -e '/general/d'\ -e '/control/d' \ -e '/junk/d' \ -e 's/</rmgroup/' \ -e 's/>/#/' !Funky!Stuff! echo x - rmgroup cat > rmgroup << '!Funky!Stuff!' #! /bin/sh # from : sdcsvax!sdcrdcf!hplabs!hao!seismo!rlgvax!cvl!umcp-cs!eneevax!chris # # @(#)rmgroup.sh (U of Maryland) FLB 28-Jun-1983 # Bug fixes 5 June 1984 Chris Torek # # Delete a newsgroup lib=/usr/new/lib/news spool=/usr/spool/news group=$* for group do qgrp="`echo $group | sed 's/\./\\\./g'`" if grep -s "^$qgrp [0-9][0-9][0-9][0-9][0-9]$" $lib/active then ed - $lib/active << xxxFOOxxx /^$qgrp [0-9][0-9][0-9][0-9][0-9]$/d w q xxxFOOxxx else echo "$0: $group: no such active line" 2>&1 fi dir=$spool/"`echo $group | sed 's/\./\//g'`" if [ -d "$dir" ] then /bin/rm -fr "$dir" else echo "$0: $dir: no spool directory" 2>&1 fi done exit 0 !Funky!Stuff! :::::::::::::: shells/5 :::::::::::::: Date: Thu, 20 Sep 84 01:20:29 pdt From: turtlevax!ken (Ken Turkowski) To: resonex!nancy Subject: Handy new uucp utility: uuque cat << EOF I just completed a new useful uucp utility which lets you know what kind of uucp work is in progress. While uusnap just tells you the number of files to be processed, uuque tells you exactly what kind of work is to be performed. I've only tried it on three kinds of work, namely mail, news, and standard uucp transfers. Give it a try, and see if it breaks on any new types of uucp work. Ken P.S. This really should be a C program. EOF echo x - uuque cat >uuque <<'!Funky!Stuff!' #! /bin/sh # uusnap cd /usr/spool/uucp LUUNAME=`uuname -l` # Check for outgoing work for cmdfile in C./* do test -f $cmdfile || continue othersys=`expr $cmdfile : 'C./C.\(.*\).....'` cmd= dfile= xfile= ufile= cat $cmdfile | { while read cmd arg1 arg2 arg3 extra do case $cmd in S) ;; *) echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra exit ;; esac case $arg1 in D.${LUUNAME}X????) # Remote execute file xfile=$arg1 ;; D.${LUUNAME}?????) # Data file ref'd by the execute file dfile=$arg1 ;; *) # Just a uucp dfile=$arg1 ufile=$arg2 from=$arg3 ;; esac done case $xfile in "") # uucp transfer echo `wc -c < $dfile`\ uucp $dfile $othersys!$ufile \($from\) ;; *) # complex transfer cat D.${LUUNAME}X/$xfile | { while read xcmd arg1 arg2 extra do case $xcmd in U) from=$arg2!$arg1 ;; F) ;; I) ;; C) echo `wc -c < D.${LUUNAME}/$dfile`\ $arg1 $othersys!$arg2 \($from\) ;; *) echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2 exit ;; esac done } ;; esac } done # Check for incoming work for cmdfile in X./* do test -f $cmdfile || continue othersys=`expr $cmdfile : 'X./X.\(.*\).....'` cat $cmdfile | { while read cmd arg1 arg2 extra do case $cmd in U) from=$arg2!$arg1 ;; Z) ;; F) if test -f D./$arg1 then dfile=D./$arg1 elif test -f D./$arg2 then dfile=D./$arg2 else continue 2 fi ;; C) xcmd=$arg1 ;; *) echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra exit ;; esac done echo `wc -c < $dfile`\ $xcmd $dfile \($from\) } done !Funky!Stuff! :::::::::::::: shells/6 :::::::::::::: Date: Sat, 22 Sep 84 01:22:39 pdt From: turtlevax!ken (Ken Turkowski) To: resonex!nancy Subject: Re: uuque I've updated uuque to the point where it should probably instead be called uusnoop. Of course, it's not that interesting unless there are others on your system that use uucp and net mail. Ken echo x - uuque cat >uuque <<'!Funky!Stuff!' #! /bin/sh # The user must have access to the /usr/spool/uucp/* directories and files. # This can be easily done by making certain users members of the daemon # and/or uucp groups, or by becoming super-user. # uusnap cd /usr/spool/uucp LUUNAME=`uuname -l` # Check for outgoing work for cmdfile in C./* do test -f $cmdfile || continue othersys=`expr $cmdfile : 'C./C.\(.*\).....'` cmd= dfile= xfile= ufile= cat $cmdfile | { while read cmd arg1 arg2 arg3 extra do case $cmd in S) # uucp send case $arg1 in D.${LUUNAME}X????) # Remote execute file xfile=$arg1 ;; D.${LUUNAME}?????) # Data file ref'd by xfile dfile=D.${LUUNAME}/$arg1 ;; *) # Just a uucp -- no intertpretation echo `wc -c < $arg1`\ uucp $arg1 $othersys!$arg2 \($arg3\) ;; esac ;; R) # uucp receive echo ' ' uucp $othersys!$arg1 $arg2 \($arg3\) ;; *) echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $arg3 $extra continue ;; esac done case $xfile in "") # uucp transfer continue ;; esac cat D.${LUUNAME}X/$xfile | { # complex transfer -- interpret xfile while read xcmd arg1 arg2 extra do case $xcmd in U) from=$arg2!$arg1 ;; F) ;; I) ;; Z) ;; C) case $arg1 in rmail) from=`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )` echo `wc -c < $dfile`\ $arg1 $othersys!$arg2 \($from\) echo -n ' ' grep '^Subject:' $dfile || echo '' ;; rnews) echo `wc -c < $dfile`\ $arg1 $othersys \($from\) echo -n ' ' grep '^Newsgroups:' $dfile echo -n ' ' grep '^Subject:' $dfile ;; *) echo `wc -c < $dfile`\ $arg1 $arg2 $extra [$othersys $dfile] \($from\) ;; esac ;; *) echo Unknown xcmd in $xfile: $xcmd $arg1 $arg2 exit ;; esac done } } done # Check for incoming work for cmdfile in X./* do test -f $cmdfile || continue othersys=`expr $cmdfile : 'X./X.\(.*\).....'` comment= cat $cmdfile | { while read cmd arg1 arg2 extra do case $cmd in U) from=$arg2!$arg1 ;; Z) ;; I) ;; F) if test -f D./$arg1 then dfile=D./$arg1 elif test -f XTMP/$arg2 then dfile=XTMP/$arg2 comment="(EXECUTING)" else continue 2 fi ;; C) xcmd=$arg1 xargs="$arg2 $extra" case $arg1 in rmail) from=$othersys!`head -1 $dfile | ( read arg1 arg2 extra; echo $arg2 )` echo -n ' ' grep '^Subject:' $dfile || echo '' ;; esac ;; *) echo Bad cmd in $cmdfile: $cmd $arg1 $arg2 $extra continue ;; esac done echo `wc -c < $dfile`\ $xcmd $xargs $comment \($from\) } done !Funky!Stuff!