OT: Cron question

Jakob Østergaard jakob at unthought.net
Fri Feb 15 16:16:36 PST 2002


On Fri, Feb 15, 2002 at 06:15:46PM -0600, gj wrote:
> use cron as a front to a script which uses formatted output from date to
> 
>   check the day of the week, if Fri
>     check day of the month, if <=7
>       execute job B
>   otherwise
>     execute job A
> 
> This could be implemented in Bourne shell script in a few minutes.
> 
> Cron doesn't really have any flow control capabilities.  Scripting is 
> the only way to go.
...

Thanks - ok, several people have suggested this, and in fact I did the script
almost immediately after the first suggestion.   Just for the record, here goes
a script to make the Amanda backup system run one backup set every first friday
in the month, and another set all other days.

It is assumed that cron runs the script as root, and with the arguments "check"
early in the day (to see if the right tape is available), and "backup" later on
for the real backup.

Use and abuse as you see fit   :)

---------------------------8<------------------
#!/bin/bash
#
# This script will either check tapes or perform
# a backup of some particular backup set, depending
# on the date, and on the argument given:
#
# argument "check" causes the script to check for tapes
# argument "backup" causes the script to run the backup
#
# the first friday in the month, the script will use "FullSet"
# on all other days it will use "DailySet"
#
DAILYSET="DailySet"
FULLSET="FullSet"

# 0 is sunday, 0-6
DAYOFWEEK=`date +%w`

# 1-31
DAYOFMONTH=`date +%d`

# Is this a friday ?
if [ $DAYOFWEEK -eq 5 ]; then
	# Is this the first week of the month ?
	if [ $DAYOFMONTH -lt 8 ]; then
		USESET=$FULLSET
	else
		USESET=$DAILYSET
	fi
else
	USESET=$DAILYSET
fi

# Check args
case "$1" in
  check)
    COMMAND="/usr/sbin/amcheck -m $USESET"
        ;;
  backup)
    COMMAND="/usr/sbin/amdump $USESET && (/usr/sbin/amverify $USESET &> /dev/null)"
        ;;
  test)
    COMMAND="echo \"Will run backup set \\\"$USESET\\\"\""
        ;;
  *)
    echo "Must use either check, backup, or test as argument"
    exit 1
esac

# echo "$COMMAND"
su amanda -c "$COMMAND"
---------------------------8<------------------


-- 
................................................................
:   jakob at unthought.net   : And I see the elder races,         :
:.........................: putrid forms of man                :
:   Jakob Østergaard      : See him rise and claim the earth,  :
:        OZ9ABN           : his downfall is at hand.           :
:.........................:............{Konkhra}...............:



More information about the Beowulf mailing list