#!/bin/bash # generate-calendar # Version: 1.0 # Created: February 8, 2006 # Created By: JMC support (at) moonpoint.com # Updated: February 8, 2006 # Description: Generates an HTML calendar for the given year. The output file # must be specified on the command line with the -o argument, # e.g. -o /example/index.html. The year must also be specified on the # command line with -y yy, e.g. -y 06. If the output file already exists # the user will be prompted as to whether it should be overwritten. # # Requires: pcal (see http://pcal.sourceforge.net/) # Available from: http://support.moonpoint.com/downloads/computer_languages/bash/generate-calendar print_usage() { echo 'Usage: generate-calendar -o output_file [-t title] [-y yy]' echo ' ' echo 'The script takes optional title and year arguments' echo ' ' echo '-o specifies the HTML output file, e.g. /example/index.html' echo '-t specifies the title and heading for the HTML file' echo ' If there is a space in the title enclose it in double quotes' echo '-y specifies the year for the calendar, e.g. 06' echo ' If no year is specified, the calendar will be created only' echo ' for the current month' } # If no arguments are included on the comand line then print # usage information and exit. if [ $# -eq 0 ]; then print_usage exit 1 fi # See page 145 of "Learning the bash Shell" for getopts information. while getopts ":o:t:y:" opt; do case $opt in o ) outfile=$OPTARG;; t ) title=$OPTARG;; y ) year=$OPTARG;; \? ) print_usage exit 1 esac done shift $(($OPTIND -1)) if [ -e $outfile ]; then echo "$outfile exists" echo -n "Overwrite (y/n)? " read Response # Translate uppercae characters to lowercase Response=`echo $Response | tr A-Z a-z` case "$Response" in y ) `pcal -H -C "$title" -o $outfile $year` exit 0;; n ) echo 'File not overwritten - exiting.' exit 1;; * ) echo 'You must enter y or n.';; esac fi `pcal -H -C "$title" -o $outfile $year`