#!/bin/ksh
#
# program: upto.
# Upto takes two arguments and counts up from the
first
# to the second. This is more a wrapper for a
function to be
# incorporated into other programs.
# author: David W. Myers
# date: 2/10/2000
# modified: n/a
#
function upto
{ [ $1 ] && F=$1 || return
[ $2 ] && S=$2 || return
(( F >= S )) && return
Temp=$F
while (( Temp <= S )) ; do
echo "$Temp "
Temp=$(( Temp + 1 ))
done
}
echo "Testing the upto function."
upto $1 $2
It needs to be noted that GNU grep has built-in recursive grepping with the "-d" and/or the "-r" flags.
#!/bin/ksh
#
# program - greptree: A program to grep a selected text
# string
across a directory and all
# subdirectories
of this directory.
#
# author : David Myers
# date: 08/24/2000
# modified: 06/13/2002
#
function Usage
{
echo "USAGE:$SCRIPT [-hq] [-v] filtertext
[directory]
This program takes filtertext and runs a grep command for
that text in directory and any subdirectory of this directory. Only
files containing text are searched. The directory defaults to the
current directory of execution if not specified.
Arguments:
-v
: verbose mode
-h
: print this message
-q
: print this message
"
if [ $1 ] ; then
exit $1
else
exit 0
fi
}
SCRIPT=${0##*/}
if [ $# -lt 1 ] ; then
Usage 2
fi
Vmode=False
while getopts "hqn:" Arg ; do
case $Arg in
v) Vmode=True ;;
*) Usage ;;
esac
done
shift $(( OPTIND - 1 ))
Filter="$1"
Target="$2"
if [ "$Target" = "." -o "$Target" = "" ] ; then
Target=$(pwd)
fi
Grep=/usr/xpg4/bin/grep
find $Target -type d -print | while read Dir ; do
cd $Dir
ls -1 | while read File; do
if [ "$Vmode" = "True" ] ; then
print "checking
$Dir/$File"
fi
file $File | $Grep -Eq
"(ascii|script|text)" &&
{
$Grep -Fq $Filter $File
&&
echo
"$Dir/$File has the text $Filter"
}
done
done
#!/sbin/sh
#
# tcptweak.
#
# fixes the cwnd problem with Sun and NT.
# also sets the interfaces to full duplex.
# there may be momentary loss of connectivity
# as this process is enabled.
#
case $1 in
'start')
NddPath=/usr/sbin
if [ -x $NddPath/ndd ] ; then
#
# Sun will not properly
autonegotiate full duplex
# transmission. This
workaround forces full duplex
# on all NICs.
#
$NddPath/ndd
-set /dev/hme instance 0
$NddPath/ndd
-set /dev/hme adv_100fdx_cap 1
$NddPath/ndd
-set /dev/hme adv_autoneg_cap 0
$NddPath/ndd
-set /dev/hme instance 1
$NddPath/ndd
-set /dev/hme adv_100fdx_cap 1
$NddPath/ndd
-set /dev/hme adv_autoneg_cap 0
#
# This gets around the
cwnd problem with Sun and NT
# TCP/IP stacks. Sun
ordinarily expects a ACK after
# 1 packet and NT ends 2.
#
$NddPath/ndd
-set /dev/tcp tcp_slow_start_initial 2
fi
;;
'stop')
#
# no special stop necessary
#
;;
*)
echo "USAGE: $0 { start | stop } "
;;
esac
#!/bin/ksh
#
# roll - a program to save n generations of files
# as file.1, file.2, etc
#
function Usage
{
echo "USAGE:$SCRIPT [-hq] [-n numbers] filename
This program take the file filename and renames it as
filename.1 It further renames filename.1 as filename.2 to n
generations of files.If the number of generations exceeds 9, it
renames as filename.01, filename.02, etc.
Arguments:
-n : number
of generations [ default $Ngen ]
-h : print
this message
-q : print
this message
"
if [ $1 ] ; then
exit $1
else
exit 0
fi
}
SCRIPT=${0##*/}
Ngen=9
while getopts "hqn:" Arg ; do
case $Arg in
n) Ngen=$OPTARG ;;
*) Usage ;;
esac
done
shift $(( OPTIND - 1 ))
if [ $1 ] ; then
Filename=$1
else
print "No filename given."
Usage 210
fi
if [ ! -f $Filename ] ; then
print " $Filename does not exist."
exit 209
fi
if (( Ngen < 1 )) ; then
print "Number of generations \"$Ngen\" less than
1."
exit 208
fi
if (( Ngen > 99 )) ; then
print "Warning: Number of gens \"$Ngen\" greater
than 99."
print "This value reset to 99."
Ngen=99
fi
if (( Ngen > 9 )) ; then
typeset -Z2 Count NewCount
else
typeset -L1 Count NewCount
fi
Path=${Filename%/*}
Name=${Filename##*/}
if [ "$Path" = "" -o "$Path" = "$Filename" ] ; then
Path="."
fi
Count=$Ngen
while (( Count > 0 )) ; do
NewCount=$(( Count - 1 ))
if (( NewCount > 0 )) ; then
NewName=$Name.$NewCount
else
NewName=$Name
fi
if [ -f $Path/$NewName ] ; then
if [ -f $Path/$Name.$Count ] ; then
rm $Path/$Name.$Count
fi
mv $Path/$NewName $Path/$Name.$Count
fi
Count=$NewCount
done
#!/bin/ksh
#
# syncit - a program for syncing data from dirs on another
machine.
#
# Note - slash needed on end of DataDir.
#
DataDir="/my/directory/"
LocalDir="/my/archive"
WorkingAcct="data@domain.com"
#
rsync -e ssh -auvz $WorkingAcct:$DataDir $LocalDir
#!/bin/ksh
#
# fetchit - a program for fetching data from dirs on another
machine.
#
DataDir="/my/directory"
LocalDir="/my/archive"
WorkingAcct="data@domain.com"
#
cd $LocalDir || { print "Cannot cd into directory
$LocalDir" ; exit 7 ; }
ssh $WorkingAcct "cd $DataDir ; find . -depth -print |
cpio -ocB" | cpio -idmuvcB