Simon's Scripts



pfctl kill scripts

for i in `pfctl -ss | grep 172.29.1.47 | grep EST | awk '{ print $3 }' | sed 's/\(.*\):.*/\1/'|uniq`; \
do echo $i; done


--------

#!/bin/sh

# This script copies files from the old pre-4.4 XFree86 install area
# to the new 4.4 XFree86 install area. The reason for this is because 
# the old CSLab XFree86 installation contains files that are 
# missing from the new CSLab XFree installation e.g. xlock, xscreensaver,etc

# Variables

# The File_List variable is generated by diff'ing /usr/X11R6.old/bin/ and 
# /usr/XFree86-4.4/X11R6/bin/ (and then removing extraneous spaces, etc).
File_List=plop

# Source_Dir = The old XFree86 installation area
Source_Dir=/usr/X11R6.off/bin	

# Destination_Dir = The new XFree86 installation area
Destination_Dir=/usr/XFree86-4.4/X11R6/bin

# Some very basic sanity checks

if [ "Linux" != "`uname -s`" ] ; then
echo "This script must be run on Linux not on `uname -s`"
exit 1
fi

if [ "`id -u`" != 0 ] ; then
echo "You must either be root or troot to run this script"
exit 1 
fi 

if [ ! -d $Source_Dir ] ; then
echo "I cannot find the source directory to copy files from"
echo $Source_Dir
echo "Are you sure you have installed the new version of XFree86?"
exit 1
fi

if [ ! -d $Destination_Dir ] ; then
echo "I cannot find the destination directory to copy the files to"
echo $Destination_Dir
echo "Are you sure you have installed the new version of XFree86?"
exit 1
fi 

if [ ! -r $File_List ] ; then
echo "I cannot find a readable copy of:" $File_List
echo "Are you sure it is there and that it is readable?"
exit 1
fi

# End of sanity checks


for BECKHAM in `cat $File_List`
do 
/usr/ucb/cp -u $Source_Dir/$BECKHAM $Destination_Dir/
done


------

#!/bin/sh

# Has this script been run before on this machine?

if [ -d /usr/X11R6.old ] ; then 
 echo "It appears that this script has been run before on this machine"
exit 1
fi

if [ -d /usr/X11R6.off ] ; then
 echo "It appears that this script has been run before on `hostname`"
exit 1
fi

# Mount filesystem that contains our XFree86 tarball

mount dixie:/export/boot/linux/RH7.3 /mnt/linux

cd /usr
tar xvf /mnt/linux/XFree86-4.4/XFree86-4.4.tar

mv /usr/X11R6 /usr/X11R6.old
ln -s /usr/XFree86-4.4/X11R6 /usr/X11R6
ldconfig
/etc/init.d/xdm stop
sleep 3
/etc/init.d/xdm start
umount /mnt/linux
sleep 15
echo "`hostname` is running: "
cat /var/log/XFree86.0.log | grep "compiled for 4.4" | gawk '{ print $3 }' | uniq
cat /var/log/XFree86.0.log | grep EE

--------------
#!/bin/sh

# phusis.cs only uses one file for pf.conf
PFCONF=pf.conf

# private key of phusis.cs
SSHKEY=keys/id_phusis_rsa

# Rudimentary checks to make sure the necessary files exist

if [ !  -f "$PFCONF" ] ; then
 echo "I cannot find $PFCONF"
 echo "Perhaps you accidently checked it in?"
 exit 1
fi

if [ ! -f "$SSHKEY" ] ; then
 echo "I cannot find $SSHKEY"
 exit 1
fi

echo""
echo "Writing out \"pf.conf\" to \"phusis.cs:pf.conf.tmp\"
and checking its syntax ...
"

# Copy local pf.conf over to server as pf.conf.tmp
# Test to make sure that pf.conf.tmp has no syntax errors
# If it passes the test, copy pf.conf.tmp to pf.conf and
# make it active. If it does not pass the test, abort

cat "$PFCONF" | ssh -i $SSHKEY root@phusis.cs.toronto.edu \
'cat > /etc/pf.conf.tmp && pfctl -n -f /etc/pf.conf.tmp \
&& mv /etc/pf.conf.tmp /etc/pf.conf && pfctl -f /etc/pf.conf'

# Catch exit code
ExitCode=$?

if [ $ExitCode = "0" ]; then
    echo "The update appears to have worked"
    echo "The exit code was $ExitCode"
else
    echo ""
    echo "Something has gone wrong ..."
    echo "The exit code was $ExitCode"
    exit $ExitCode
fi

-----------------------------------------------------
#!/bin/sh

# This script does a lukewarm job of creating HTML 
# pages from DNS zone files on keele.cs

# Variables

TARGET=/h/20/simon/webnotes/vlans/dns/
SOURCE=/slocal/bind9/lvar/internal/

# The idea here is to read off all the .local zone files
# in the bind9 repository and then pump out the relevant
# entries to separate files under my/our webnotes directory
# Please note I removed the < and the > from the html tags
# because it was messing up this web page !!

for LOOP in `ls $SOURCE | /local/bin/grep ".local"`
do
echo "HTMLHTMLHEADTITLE/TITLE/HEADBODYH3" > $TARGET$LOOP
echo `date` >> $TARGET$LOOP
echo "/H3PRE" >> $TARGET$LOOP
cat $SOURCE$LOOP | /usr/bin/sed 's/>/\>/g' | /usr/bin/sed 's/> $TARGET$LOOP 
echo "/PRE/BODY/HTML" >> $TARGET$LOOP
done

--------------------------------------------------------

#!/bin/sh

SSHKEY=/h/20/simon/private/firewall-backups/keys/id_fw_rsa
FIREWALL="pavise.dev2.local"
DESTDIR="/h/20/simon/private/firewall-backups/pavise"


while read LINE
do 
if [ ! -d  `echo ${DESTDIR}${LINE} | sed 's/\(.*\)\/.*/\1/'` ]; then
   mkdir -p `echo ${DESTDIR}${LINE} | sed 's/\(.*\)\/.*/\1/'` &&
   /local/bin/scp -i $SSHKEY root@$FIREWALL:${LINE} ${DESTDIR}${LINE} > /dev/null 2>&1
else
 /local/bin/scp -i $SSHKEY root@$FIREWALL:${LINE} ${DESTDIR}${LINE} > /dev/null 2>&1
fi

done < $DESTDIR/files.txt

--------------------------------------------------------------

#!/bin/sh

SSHKEY=/h/20/simon/private/firewall-backups/keys/id_fw_rsa
FIREWALL="128.100.27.193"
DESTDIR="/h/20/simon/private/firewall-backups/SITE_TGZ"
FILESLIST="donkey1_files_bkup"

# Let us first take out all lines in $FILESLIST that either begin with 
# a comment (#) or a space or not a "/" and not an alpha-numeric character.
# Strip the leading "/" and pipe the file to the FW. Next "cd /" on the 
# FW and run tar


cat "${FILESLIST}" | egrep -v "#" | grep "^[/a-zA-Z0-9]" | sed 's/^\///'| \
/local/bin/ssh -i $SSHKEY root@$FIREWALL \
' cd / && cat > FWLIST && /usr/sbin/pkg_info > donkey1_packages && echo donkey1_packages >> FWLIST ' && \

( 
  /local/bin/ssh -i $SSHKEY root@$FIREWALL 'cd / && tar -I FWLIST -cf -'  | dd of=$DESTDIR/donkey1.tar && \
  /local/bin/scp -i $SSHKEY root@$FIREWALL:/donkey1_packages /$DESTDIR/donkey1_packages
) 2>${FIREWALL}_ERRLOG

--------------------------------------------

This will list only the package name:

cat /root/build_scripts/PACKAGES/PKGLIST | sed 's/\(.*\)-[0-9].*/\1/g'
or 
cat SITE_TGZ/donkey1.packages | sed 's/\([-a-zA-Z0-9]*\) .*/\1/g'

And then find the port in the tree:

find /usr/ports/ -maxdepth 2 -name gettext

#!/bin/sh

FIREWALL="pavise"
SOURCE="/h/20/simon/private/firewall-backups/${FIREWALL}/"

SSHKEY=/h/20/simon/private/firewall-backups/keys/id_fw_rsa
DESTDIR="/h/20/simon/private/firewall-backups/SITE_TGZ"
FILESLIST="${FIREWALL}-files"


# First of all, remove all lines in $FILESLIST that begin with a comment or a space.
# Then remove all lines that do not begin with a "/" nor an alpha-numeric character.
# Next strip the leading "/" and pipe the file to the FWLIST 

cat "${SOURCE}${FILESLIST}" | egrep -v "#" | grep "^[/a-zA-Z0-9]" | sed 's/^\///' | \
/local/bin/ssh -i $SSHKEY root@$FIREWALL \
" cd / && cat > FWLIST && /usr/sbin/pkg_info > ${FIREWALL}.packages && echo ${FIREWALL}.packages >> FWLIST " && \

( 
  /local/bin/ssh -i $SSHKEY root@$FIREWALL 'cd / && tar -I FWLIST -cf -'  | dd of=$DESTDIR/${FIREWALL}.tar && \
  /local/bin/scp -i $SSHKEY root@$FIREWALL:/${FIREWALL}.packages /$DESTDIR/${FIREWALL}.packages
) 2>${SOURCE}${FIREWALL}_ERRLOG


while i=`ls | grep gz`; do gunzip $i; done

--------------------------------------------------------------------

cat main.cf | ssh -l simon cs.toronto.edu 'cat | lpr -Plw-staff'

---------------------------------------------------------------------

A couple of silly while loops ...

  #!/bin/sh

  # This script simply prints out a sequence of numbers
  COUNTER=0
  #while [ $COUNTER -lt 5 ]
  while [ 1=1 ]
  do
  COUNTER=`expr $COUNTER + 1`
  echo $COUNTER
  done

  #!/bin/sh

  COUNTER=0
  while [ $COUNTER -lt 50000 ]
  do
  sleep 1
  COUNTER=`expr $COUNTER + 1`
  DATE=`date|awk '{print $4}'`
  echo $DATE
  cd mailraid
  touch $DATE
  cp $DATE ..
  cd ..
  done
-------------------------

Simple 'mail' stuff


 mail -s 'my subject heading' simon < /tmp/junk

or:

 echo test | mail -s 'my subject heading' simon,simontst

--------------------------------------
======================================


#!/bin/sh

#Do not edit this file directly
#Edit lachesis-template instead

BOOTDISK=wd0
SWAPDISK=wd0
DISK_SET="wd0"


#--------------------
# TimeZone
#--------------------

TIMEZONE=Canada/Eastern

#--------------------
# Install Sets
#-------------------

INSTALL_SET="base36 etc36 man36 comp36 misc36 site36"

#-----------------------------------------------------
# Script Begins 
#-----------------------------------------------------

# Initialize all the disks

for i in $DISK_SET; do

fdisk -e $i <<  FDISK
reinit
update
write
quit

FDISK

echo "$i has been fdisked using fdisk -e"
done

# Add a disklabel to each disk on the machine
# The disklabel must already exist

for i in $DISK_SET; do
 ftp -m http://$INSTALL_SERVER/FIREWALLS/$HOSTNAME/DISKS/${i}-disklabel 
 disklabel -R $i ${i}-disklabel
 echo "$i ${i}-disklabel is done"
done

# Format each disk and its partitions defined in the disklabel file.

# "cat wd0-disklabel | egrep "^  [^bac]" | sed 's/  \([a-z]\):.*/\1/g"
# shows the partitions for each disk. Please note that partitions "a, b 
# and c" on wd0 are default partitions.

# Format and mount "/" first

newfs -q /dev/r${BOOTDISK}a
mount /dev/${BOOTDISK}a /mnt

# Format the rest of the partitions

for i in $DISK_SET; do
 echo $i
 if [ "$i" = "${BOOTDISK}" ]; then

 for j in `cat ${i}-disklabel | egrep "^  [^abc]" | sed 's/  \([a-z]\):.*/\1/g'`; do
  newfs /dev/${i}${j}
  done

  else
  for k in `cat ${i}-disklabel | egrep "^  [^c]" | sed 's/  \([a-z]\):.*/\1/g'`; do
  newfs /dev/${i}${k}
  done

 fi
done


# Now mount each partition according to /etc/fstab
ftp -m http://$INSTALL_SERVER/FIREWALLS/$HOSTNAME/DISKS/fstab

egrep -v "${BOOTDISK}a"  fstab | while read PARTITION MOUNTPOINT JUNK
do
 echo "mkdir /mnt${MOUNTPOINT}"
 mkdir /mnt${MOUNTPOINT}
 mount $PARTITION /mnt${MOUNTPOINT}
 echo "mount $PARTITION /mnt${MOUNTPOINT}"
done
for i in bsd bsd.rd; do
    ftp -o /mnt/$i -m http://$INSTALL_SERVER/RELEASE/$i
done

for i in $INSTALL_SET; do
 ftp -o - -m http://$INSTALL_SERVER/RELEASE/${i}.tgz | tar zxphf - -C /mnt
done

ftp -o /mnt/etc/fstab -m http://$INSTALL_SERVER/FIREWALLS/$HOSTNAME/DISKS/fstab

# Install a stub master.passwd file
# Make sure that all references to /usr/local/bin/bash for root are removed
# bash is not yet installed


echo "Installing a stub master.passwd file"

ftp -o /mnt/etc/master.passwd -m http://$INSTALL_SERVER/FIREWALLS/common/master.passwd
/mnt/usr/sbin/pwd_mkdb -p -d /mnt/etc /etc/master.passwd

echo "Setting TimeZone to $TIMEZONE"

ln -sf /usr/share/zoneinfo/$TIMEZONE /mnt/etc/localtime

echo "Configuring swap space on ${SWAPDISK}b and running MAKEDEV all"

/mnt/sbin/swapctl -a /dev/${SWAPDISK}b
( cd /mnt/dev && sh MAKEDEV all )

# Setting hostname for the install.site script that runs later
hostname $HOSTNAME

echo "Generating the host.random file"
dd if=/mnt/dev/urandom of=/mnt/var/db/host.random bs=1024 count=64
chmod 600 /mnt/var/db/host.random

echo "Installing boot blocks"

cat /usr/mdec/boot >/mnt/boot
/usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot ${BOOTDISK}
echo "install.site being run"
sh /mnt/install.site

----------------------------------------

(
APLIST="/scripts/ap/ap-list"
numdown=0
PINGS=2

echo
echo " Unreachable Wireless Access Points"
echo "------------------------------------"
printf "\nIP\t\tRoom\tInfo\n"
echo "------------------------------------"


grep -v "^#" $APLIST | grep "^[0-9]" >> $$.tmp

while read IPADDRESS LOCATION DESCRIPTION
do
        if ! ping -c $PINGS $IPADDRESS > /dev/null
        then
                numdown=`expr $numdown + 1`
                printf "%s\t%s\t" $IPADDRESS $LOCATION
                echo "$DESCRIPTION"
        fi
done < $$.tmp

rm $$.tmp

if [ $numdown -eq 0 ]
then
        echo ""
        echo "ALL ACCESS POINTS ARE UP!!"
        echo ""
        NUMBER=`ps | sum | cut -c4-5`
          if [ $NUMBER = 00 ] || [ $NUMBER = 0 ]
         then
          echo "There is no vegetable of the day today ... sorry"
         else
         VEGGIE=`cat /scripts/ap/VEGGIES | sed -n "${NUMBER}p"`
         echo ""
         echo ""
         echo "Vegetable of the day is: $VEGGIE"
 fi
fi
echo "------------------------------------"
echo

echo
echo "This script runs on wirewall as /scripts/ap/pingaps.sh"
echo "It runs out of cron."
echo
echo "The list of Access Point is on keele.cs in:"
echo "/private/firewalls/firewall-admin/wirewall/ap/ap-list"
echo
echo "If you want to update the list of Access Points, please"
echo "go to /private/firewalls/firewall-admin/wirewall/ap/"
echo "and consult the 'ap-list' file for instructions."
echo
) > FRED-tmp 2>&1 && cat FRED-tmp | /usr/bin/ssh -i /root/KEYS/privatekey root@keele.cs.toronto.edu 'cat | mail -s "Access Points Status" nico, ops'


# Change 'machine.cs;;' -> 'machine.cs':

 cat FRED | egrep -v # | sed 's/\([a-z].*\),,/\1/g'



# rsync 

# export RSYNC_RSH=ssh
# echo $RSYNC_RSH
ssh
# rsync -a SAVED sandiego.cs.toronto.edu:/h/281/BADARMOURY


======================================================================


 #!/bin/sh
  COUNTER=0
  while [ $COUNTER -lt 15 ]
  do
  COUNTER=`expr $COUNTER + 1`
  echo QUIT | telnet imap.cs.toronto.edu 110
  done

==========================================================================


/var/log/console# tar -cf - . | ssh set@yenta "cd LogsFromOldConserver && tar -xf -"


# How to get a list of machines from nmh, search 

From this:

201  08/07 06:25 root    urd: new Ubuntu updates

To this:

 urd

Do this:
 
 pick -search "new Ubunbtu updates" 

 scan picked | awk '{ print $5}' | sort | uniq | sed 's/\([a-z].*\):/\1/g'

Find and Odd Xters
==================

The way to get around spaces and other weird chars in file names is:

  find . -group millgrp -print | sed 's/^/"/;s/$/"/' | xargs chgrp -h millres

  i.e.

  echo fred\ the\ dog | sed 's/^/X/' | sed 's/$/X/'  = "Xfred the dogX"

Finding files with specific permissions ... 

Please change all the world readable files in "some_folder" owned by oldpkgs to
be owned by lstaff. Please note that most the files were created on Windows boxes
(read here that they probably have spaces in them):

   find . -group oldpkgs
   find . -perm -g=r
   sed 's/^/"/;s/$/"/'
   chgrp -h lstaff

  find . -group oldpkgs -perm -o=r | sed 's/^/"/;s/$/"/' | xargs chgrp -h lstaff

But here is another way to do this which is probably better
-----------------------------------------------------------

Please chgrp all of the world readable files in "some_folder", owned by anyone
except lstaff, to be owned by lstaff. Please also adjust the permissions on those
files so that the world writable bit is removed (some of these files will have 
spaces in their names).



  find . ! -group lstaff -perm o=r -exec chmod 755 {} \; -a -exec chgrp lstaff {} \;

  Apparently the 'exec' command will allow you to manipulate file names with spaces.


Here is my task:

Please chgrp all of the world readable files in "some_folder", owned by
anyone except lstaff, to be owned by lstaff. Please also adjust the
permissions on those files so that the world writable bit is removed
(some of these files will have spaces in their names).

So we have two finds and then two commands to run. In addition "fred the
dog" has spaces.

This command seems to sort it:

find . ! -group lstaff -perm -o=r -exec chgrp lstaff {} \; -a -exec chmod o-r  {} \;


drwxr-xr-x 3 simon lstaff     6 2008-12-16 16:26 .
drwxr-xr-x 9 simon lstaff    20 2008-12-10 14:57 ..
-rwxr-x--x 1 simon lstaff     0 2008-12-16 09:29 fred the dog
-rwxr-x--x 1 simon lstaff     0 2008-12-16 14:02 stripey
drwxr-x--x 3 simon lstaff     6 2008-12-16 14:39 subfolder
-rwxr-x--x 1 simon lstaff 41984 2008-10-17 15:49 whatapdoes.doc


It looks to me as if you run the 'chmod' via an exec, the spaces do not
matter. In addition, you do not run into the xargs limitation of too
many files.

In an even simpler case, where you are looking to run only one command
after a find (but again you have file names with spaces), you can also
do the following.

Please chmod 755 all of the files listed above.

 ls
 -rwxr-x--x 1 simon lstaff     0 2008-12-16 09:29 fred the dog

 find . -print0 | xargs -0 chmod 755

 ls
 -rwxr-xr-x 1 simon lstaff     0 2008-12-16 09:29 fred the dog

 The '-print0' combined with the 'xargs -0' replaces spaces with NUL
 characters  ...

--------------------

I have two files that I wish to join:

fruit:
 apples
 oranges
 pears

colours:

 blue
 pink
 yellow

I want output of the sort:

 blue apples
 pink oranges
 pears yellow

Answer:

 paste -d' ' colours fruit


Some more sed junk ...

1. Convert 'cats and dogs' to 'cats and dogs and fish'
   echo cats and dogs | sed 's/dogs/& and fish/'

2. Convert 'fish fish fish' to 'fish fish rice'
   echo fish fish fish | sed 's/fish/rice/3'

3. Convert 'fish fish fish' to 'fish and chips'
   echo fish fish fish | sed 's/fish/and/2' | sed 's/fish/chips/2' 
   [ remember that the first subsitution removes the number of fish 
     from 3 to 2 ]


2. Convert 'fish fish fish' to 'fish fish rice'
   echo fish fish fish | sed 's/fish/rice/3'

3. Convert 'fish fish fish' to 'fish and chips'
   echo fish fish fish | sed 's/fish/and/2' | sed 's/fish/chips/2' 
   [ remember that the first subsitution removes the number of fish 
     from 3 to 2 ]



2. Convert 'fish fish fish' to 'fish fish rice'
   echo fish fish fish | sed 's/fish/rice/3'

3. Convert 'fish fish fish' to 'fish and chips'
   echo fish fish fish | sed 's/fish/and/2' | sed 's/fish/chips/2' 
   [ remember that the first subsitution removes the number of fish 
     from 3 to 2 ]



2. Convert 'fish fish fish' to 'fish fish rice'
   echo fish fish fish | sed 's/fish/rice/3'

3. Convert 'fish fish fish' to 'fish and chips'
   echo fish fish fish | sed 's/fish/and/2' | sed 's/fish/chips/2' 
   [ remember that the first subsitution removes the number of fish 
     from 3 to 2 ]



2. Convert 'fish fish fish' to 'fish fish rice'
   echo fish fish fish | sed 's/fish/rice/3'

3. Convert 'fish fish fish' to 'fish and chips'
   echo fish fish fish | sed 's/fish/and/2' | sed 's/fish/chips/2' 
   [ remember that the first subsitution removes the number of fish 
     from 3 to 2 ]

4. I want to print the first 5 lines of the file 'myfile'
   sed 5q myfile

5. I want remove trailing blank spaces:

   echo "Here          " | sed 's/[\t]*$//'

   I want to add 'Fred' to the end of the line:

   echo "Here          " | sed 's/[\t]*$/Fred/'

6. Convert list to double-spaces:

   sed G nameoflistfile
   
7. Convert "cats and dogs" to "cats dogs"
   echo "cats and dogs" | sed s'/\(.*\) and\(.*\)/\1\2/'

8. Convert "cats and dogs" to "and":
   echo "cats and dogs" | sed s'/.*\(and\).*/\1/'

9. Convert "cats and dogs" to "nothing and nothing":
   echo "cats and dogs" | sed s'/.*\(and\).*/nothing \1 nothing/'

10. Convert "fs df dfdf dff dfff 128.100 dds fdf" to "128":
    echo fs df dfdf dff dfff 128.100 dds fdf  | sed s'/.*\(128\).*/\1/

11. Convert "dff dfff 123.456.333.567 dds fdf" to "123.456.333.567":
    echo dff dfff 123.456.333.567 dds fdf | sed 's/.* \([0-9].*\) d.*/\1/'
    
12. Convert "log.20090305164953.0" to "20090305164953":
    echo log.20090305164953.0 | sed 's/log\.\([0-9]*\)\..*/\1/'
    
13. Convert "  FRED   CAT   FRED " to "FREDCATFRED"
    echo "     FRED   CAT   FRED " | sed 's/ //g'

  ================================

Check the time stamp on a file and see if it older than a set time

 Time Of Modification (TOM)
 TOM=`stat -c=%Y $TMP | awk -F"=" '{ printf $NF }'`
 JERRY=`date +%s`
 echo TIME DIFF IN SECONDS: `expr $JERRY - $TOM`

 if [ $(( `date +%s` - $TOM )) -gt 1800 ]; then 
 echo "$TMP is older than 30 minutes/1800 seconds"
 fi
 
-------------------------------

Extend pattern matching

 ls 
 demo1  demo1.c  demo2 gen-group.sh
 shopt -s extglob
 ls !(*demo*) 
 gen-group.sh

Rules

 
  ?(pattern-list) Matches zero or one occurrence of the given patterns
  *(pattern-list) Matches zero or more occurrences of the given patterns
  +(pattern-list) Matches one or more occurrences of the given patterns
  @(pattern-list) Matches exactly one of the given patterns
  !(pattern-list) Matches anything except one of the given patterns
 

---------------------------

Converting two columns in a file to a single column:

Here is the file:

 one four
 two five
 three six
 seven ten
 eight eleven
 nine twelve

I want it in a single column in numerical order.

Note that the numbers are grouped in blocks of three so will leverage
that to sort it correctly

Here is the script:

 OUTER=1

 cat data | while read columns
 do
  echo $columns | awk '{print $1}'
  OUTER=`expr $OUTER + 1`

  if [ `expr $OUTER % 3` -eq 1 ]; then
  FIRST=`expr $OUTER - 3`
  LAST=`expr $OUTER - 1` 
  cat data | sed -n "$FIRST,$LAST"p | awk '{print $2}'
  fi
 done

Pretty ham fisted but there you go. 

Move Home Dirs
-------------

Assume:

 /home/fred
 /home/stripey

1. Move 'fred' into stripey:

   (cd /home/ && tar cf - fred ) | ( cd /home/stripey && tar xvpf - )

2. Move contents of 'fred' into stripey:

   (cd /home/fred && tar cf - . ) | ( cd /home/stripey && tar xvpf - )


3. Use ssh to move 'fred' into stripey:

   (cd /home && tar cf - fred ) | ssh pylos "( cd /home/stripey &&  tar xvpf - )"

   Or:

   ssh pylos "tar -C /home/ -czpf - fred"  | tar xzpf - -C /home/stripey

   Note that it is important to change dir before running the tar else
   you will end up with the whole directory's path included when it is copied
   over.