Asterisk Greetings Based on Time and Date
Place this in your agi-bin directory (usually /var/lib/asterisk/agi-bin):
!/bin/sh TODAY=date +%m%d%y
TODAYSHORT=date +%m%d
DAY=date +%a
HOUR=date +%H
MINUTE=date +%M
TIMENOW=$HOUR$MINUTE STATUS=closed case "$TODAYSHORT" in 0101 ) STATUS=holiday;; # New Years Day 0704 ) STATUS=holiday;; # July Forth 1224 ) STATUS=halfday;; # Christmas Eve 1225 ) STATUS=holiday;; # Christmas Day 1226 ) STATUS=holiday;; # Year End holiday 1227 ) STATUS=holiday;; # Year End holiday 1228 ) STATUS=holiday;; # Year End holiday 1229 ) STATUS=holiday;; # Year End holiday 1230 ) STATUS=holiday;; # Year End holiday 1231 ) STATUS=holiday;; # Year End holiday esac case "$TODAY" in 090505 ) STATUS=holiday;; # Labor Day 112405 ) STATUS=holiday;; # Thanksgiving 112505 ) STATUS=holiday;; # Day after ThanksGiving 052906 ) STATUS=holiday;; # Memorial Day 090406 ) STATUS=holiday;; # Labor Day 112306 ) STATUS=holiday;; # Thanksgiving 112406 ) STATUS=holiday;; # Day after ThanksGiving 052807 ) STATUS=holiday;; # Memorial Day 090307 ) STATUS=holiday;; # Labor Day 112207 ) STATUS=holiday;; # Thanksgiving 112307 ) STATUS=holiday;; # Day after ThanksGiving 052608 ) STATUS=holiday;; # Memorial Day 090108 ) STATUS=holiday;; # Labor Day 112708 ) STATUS=holiday;; # Thanksgiving 112808 ) STATUS=holiday;; # Day after ThanksGiving esac if test "$STATUS" != "holiday" -a \ "$DAY" != "Sat" -a \ "$DAY" != "Sun" -a \ "$TIMENOW" -gt "0800" -a \ "$TIMENOW" -lt "1900" then STATUS=open fi if test "$STATUS" = "halfday" -a \ "$TIMENOW" -gt "0800" -a \ "$TIMENOW" -lt "1200" then STATUS=open fi if test "$DAY" = "Sat" -a \ "$TIMENOW" -gt "0900" -a \ "$TIMENOW" -lt "1600" then STATUS=open fi if test "$DAY" = "Sun" -a \ "$TIMENOW" -gt "0900" -a \ "$TIMENOW" -lt "1300" then STATUS=open fi if test "$STATUS" = "holiday"; then STATUS=closed fi echo "SET VARIABLE status $STATUS """
The above script can be used with extensions.conf as follows :
exten => s,1,Wait,2 ; Allow for PRI to grab info in facility exten => s,2,AGI(openclose.agi) exten => s,3,GotoIf($[${STATUS} = closed]?6:4) exten => s,4,GotoIf($[${STATUS} = holiday]?8:10) exten => s,5,Goto(s,12) exten => s,6,BackGround(nighttime-greeting) exten => s,7,Goto(s,12) exten => s,8,BackGround(holiday-greeting) exten => s,9,Goto(s,12) exten => s,10,BackGround(daytime-greeting) exten => s,11,NoOp exten => s,12,BackGround(mainmenu)