#!/bin/bash
# *************************************************************
# file trigger.inc.sh
# date: 2006-02-15 09:59
# author: Marko Schulz - <mschulz@jamba.net>
# description: Check interval if an script can start.
# *************************************************************
#
#
# SYNOPSIS
#
# # load this file in your main script:
# test -f ./trigger.lib && source ./trigger.lib || exit 1
#
# First argument is the path to an date file. Second argument
# is the interval: Hourly(H), Daily(D), Weekly(W), Monthly(M).
# ! ( trigger '/path/to/datefile.txt' 'D' ) && exit 0
# date +'%Y-%m-%d %H:%M:%S' > /path/to/datefile.txt
#
# # here beginns your program...
#
# *************************************************************
function trigger () {
file=$1
date=$( date +'%Y-%m-%d %H:%M:%S' )
[ ! -f "$file" ] && ( echo "no file defined" ) && exit 1
case "$2" in
h|H)
# Hourly - get hour from date...
temp=$( echo $date | cut -d: -f1-2 )
if [ "$( cat $file | cut -d: -f1-2 )" != "$temp" ]; then
true
else
false
fi
;;
d|D)
# Daily - get day from date...
temp=$( echo $date | awk '{ print $1 }' )
if [ "$( cat $file | awk '{ print $1 }' )" != "$temp" ]; then
true
else
false
fi
;;
w|W)
# Weekly - get week from date...
# ???
;;
m|M)
# Monthly - get month from date...
temp=$( echo $date | cut -d- -f1-2 )
if [ "$( cat $file | cut -d- -f1-2 )" != "$temp" ]; then
true
else
false
fi
;;
*)
echo "modus is not a valid argument"
exit 1
;;
esac
}
# *************************************************************
# end of this library...