#!/bin/sh ############ ping_h ############# # I had a friend who needs to make sure that # should the lease on a PPPoE line run out. His # router will receive a request to bring the connection # backup. This program runs in the background and pings # google every 10 mins. # ############################################# ping -i 600 216.239.51.101 & #!/bin/sh ############# chmod_all_644 ############# # One of the examples from the find lecture all # wrapped up in a script ## finds all the files starting in the CWD ## and changes the permissions to ## rw-r--r-- ############################################# find ./ -type f -exec chmod 644 '{}' \; #!/bin/sh ############# mac2unix ############# # This is an example from the first chapter of # Unix Power Tools. 'tr' stands for translate # It can also work on ranges as you will see in the # lower_case script. # a for loop in the shell needs a 'do' and 'done' # '$*' stands for all the arguments this command has received. # '$1' would stand for the first argument. # '$0' for the name of the command # (ask me about the rc0-6.d directories) ############################################# for macfile in $* do tr '\015' '\012' <$macfile >$macfile.unix done #!/bin/sh ############################################ ############ lower_case ############# echo "this is $*" for name in $* do newname=`echo $name | tr A-Z a-z` echo "$name -> $newname" mv $name $newname done #!/bin/sh ############# sed_subst ############# # Here is a sed substitution you should be able to # figure out ... :). What do the -n and p do? ############################################# ls | sed -n 's/\(.*\)\.help\(.*\)/mv & \1\2/p' #!/bin/sh ############# lws ############# # I have an apple laser-printer which uses a command # called 'pap'. pap is kind of weird as it looks for it's # configuration file in ./.paprc or in English this current # working directory. Meaning I would have to copy the .paprc # file into every directory I would want to print from # ... annoying. So I can just put 'lws' in as the print command # in every program that I can print from. ############################################# case $# in 0) echo "Printing from standard input:" 1>&2 ;; esac pap -p "LaserWriter Select 610" $* #!/bin/sh ############# mv_save_mozilla ############# # When you save web pages from mozilla it copies down # all the images and things from the page and saves it in a # directory filename_file. this command helped me clean out # some directories littered with downloaded pages. ############################################# for file in `ls *.html`; do mv $file info/ ; dir=`echo $file | sed -n 's/\(.*\).html/\1_files/p'`; if [ -d $dir ] then mv $dir info/ ; fi done #!/bin/sh ############# monthly_mail_bkup ############# # To keep my mail boxes to a manageable size I run this # script from a crontab every month. ############################################# cd ~/Mail mydate=`date +%m-%d-%Y` files=`find ./ -type f -size +1024k -maxdepth 1 -printf "%f "` for file in $files do case $file in #I don't want to backup upper case files #damn case doesn't take ranges [QWERTYUIOPASDFGHJKLZXCVBNM]*) ;; *) newfile=$file-$mydate if [ ! -e ./$file.bk ]; then echo "making ./$file.bk" mkdir ./$file.bk fi echo "moving $file to ./$file.bk/$newfile" mv $file ./$file.bk/$newfile ;; esac done #!/bin/sh ############# cd_find ############# # I had a bunch of CD's of backed up files and needed to print out # contents liners. Needed to automate it because I had a lot # of disks. # # There are a few scripts in this series. # cd_find and cd_untar get the lists of filenames off the CD # I pipe one of these into cd_ltr_cd which will make nice ps # files for me which I can send right to my printer. ############################################# case $# in 0) depth=2 ; echo "using depth = $depth" 1>&2 ;; 1) depth=$1 ;; *) echo "whooah only two arguments name and number of columns: " ; exit 2 ;; esac ## finds the contents of the cd onto ## cd sized squares two up in a ps file ready for printing ## this module only works if you burned your CD's in ## anonymous mode (in Xcd roast) find /mnt/cdrom/ -path '*.Apple*' -prune -o -maxdepth $depth -printf '>>%m%d<%f\n ' | grep -v '5550' | ## the sed script uses the default ## permissions to make the difference btw files and directories. sed 's/>>5551<\(.*\)/\1\// s/>>4442>4441>5552<\(.*\)/ \1\// s/>>4443>5553<\(.*\)/ \1\//' #!/bin/sh ############ cd_untar ############# ############################################ for file in `ls /mnt/cdrom` do if [[ `echo $file | sed 's/.*tar.gz$/tgz/'` == tgz ]] && [ "$file" != "configFiles.tar.gz" ] && [ "$file" != "dotfilesbkup.tgz" ] then echo $file tar tzf /mnt/cdrom/$file | grep -v 'other' | grep -v '/.*/..*' | sed 's:[^/]*/\(.*\):> \1:' else if [ -d /mnt/cdrom/$file ] then echo "$file/" find /mnt/cdrom/$file -maxdepth 1 -printf "> %f\n" else echo $file fi fi done #!/bin/sh ############# cd_ltr_cd ############# # 'case' is checking the number of arguments and adding defaults # should there be no arguments. needs an 'esac' ############################################# case $# in 0) name="cd_cover" ; cols=3 ;; 1) name=$1 ; cols=3 ;; 2) name=$1 ; cols=$2 ;; *) echo "whooah only two arguments name and number of columns: " ; exit 2 ;; esac echo "printing $cols columns to file ~/$name.ps" 1>&2 ; ## make columns, and paginate ## this has to be synchronized with the a2ps or the pagination gets all messed up pr --columns=$cols -l62 -S -W 94 | ## get rid of blank lines from pr grep -v '^$' | ## you must define the paper media ## Medium: ltr_cd 612 792 135 45 477 747 ## in your .a2ps/a2psrc file ## and make sure that you have no footers defined ## as that will mess up the pagination a2ps -f6 --stdin=$name --medium=ltr_cd -o ~/$name.ps #!/bin/sh ############# filesize ############# # an awk script ! # parses the 'ls -l' command for the 5th and 9th arguments # pretty prints a line using printf. # Uses the BEGIN and END blocks to calculate values across # multiple lines which sed can't do. # See Unix Programming Environment for the best explanation # of awk. ############################################# find . -type f -exec ls -l {} \; | \ awk 'BEGIN {tsize=0; fcnt=1;} \ { printf("%03d File: %-060s size: %d bytes\n", fcnt++, $9, $5); \ tsize += $5; } \ END { printf("Total size = %d Average file size = %.02f\n", \ tsize, tsize/fcnt); } ' #!/bin/sh ############# serial_midi ############# # really long command line for a module # needed it's own script ############################################# /sbin/modprobe snd-serial-u16550 snd_port=0x3f8 snd_irq=4 snd_adaptor=1 snd_speed=19200 ############# co_all ############# # rcs is a version control system. REALLY handy # I hope we have the time to discuss it. ############################################# for file in RCS/*; do co `echo $file | sed 's/RCS\/\(.*\),v/\1/'`; done #!/bin/sh ############# cvs_co_jack ############# # CVS command lines are much too long to remember. # so rather than risk losing these from my history (remember Ctrl^r) # I made these line which will update my copy of the source code of # two projects I am interested in keeping really up to date. ############################################# cd /usr/local/src ; cvs -d :pserver:anonymous@cvs.jackit.sourceforge.net:/cvsroot/jackit -z3 co jack #!/bin/sh ############################################ ############ ardour_cvs ############# cd /usr/local/src ; cvs -z3 -d:pserver:anonymous@cvs.ardour.sourceforge.net:/cvsroot/ardour co ardour #!/bin/sh ############# ardour_startup ############# # I always need to start these two programs together: ### This script starts jack and then ardour ### ############################################# jackd -Rv -d alsa & $(cd /usr/local/src/ardour/gtk_ardour; ./ardour) #!/bin/sh ############# radio_stream ############# # This is one version of the program we use to broadcast the # radio show. (when Ruben's server is up). The current version # is more complicated because we broadcast two streams and # write one to disk. Two pipes need a fifo. ############################################# ecasound -f:16,2,44100 -i /dev/dsp \ -o stdout | \ lame -a -m m -x \ --resample 22050 -b 32 \ --tt "my cd player" \ --ta "whoever might be" \ --tl "whatever might be" \ --tc "this is a 100% free software soln" \ --ty "2002" \ - - | icecast_conn