refined shell scripts

Lee Sonko (lee@networks.bgs.com)
Mon, 7 Apr 1997 20:34:23 -0400 (EDT)


I've refined a couple of the Unix shell scripts so they behave better.
It's short enough to put all the code right here. Here they are:

These will need just a little customization for your location.
enjoy,

desstart---------
#!/bin/sh
hostname=`/usr/bin/hostname`
# Most of my network is on an NFS mount but two systems aren't and the directory structure is different.
if [ "$hostname" = "system1" ] || [ "$hostname" = "system2" ]
then
desdir="/home/xxx"
else
desdir="/home/yyy"
fi

"$desdir"desrun 2>&1 | /usr/bin/mailx -s "DES hunting `/usr/bin/date +%D` on `/usr/bin/hostname`" my@address.com &

desrun-----------
#!/bin/sh
ECHO="/usr/bin/echo"

hostname=`/usr/bin/hostname`
if [ "$hostname" = "system1" ] || [ "$hostname" = "system2" ]
then
desdir="/home/xxx"
else
desdir="/home/yyy"
fi

$ECHO "hostname = `/usr/bin/hostname`"
$ECHO "start time = `/usr/bin/date`"

# This is the only way I can think of to grab the PID...
(/usr/bin/sleep 2; $ECHO "PID = `/bin/ps -e -o pid -o args | /usr/bin/grep deschall | /usr/bin/grep -v grep | /usr/bin/awk '{print $1}'`")&

$ECHO "\n"
"$desdir"deschall keymaster.verser.frii.com
$ECHO "\n"
$ECHO "end time = `/usr/bin/date`"

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

# /usr/bin/echo "killing `/bin/ps -e -o pid -o args | /usr/bin/grep deschall | /usr/bin/grep -v grep | /usr/bin/awk '{print $1}'`"

deschall=`/bin/ps -e -o pid -o args | /usr/bin/grep deschall | /usr/bin/grep -v grep | /usr/bin/awk '{print $1}' | /usr/bin/tr -s '\012' " "`


if [ "$deschall" ]
then `/usr/bin/kill $deschall`
fi

crontab------------
# minute hour day month day (0=sun)
# run desstop on the quarter hour all day just in case something went wrong
# when we asked to kill it before.
#
# Weekdays
0 20 * * 1-5 /home/desstart
0 0 * * 1-5 /home/desstart
0,15,30,45 5-18 * * 1-5 /home/desstop
#
# Weekends
0 18 * * 0,6 /home/desstart
0 0 * * 0,6 /home/desstart
0,15,30,45 8-17 * * 0,6 /home/desstop
#
#