#!/usr/bin/bash
# execute shell script
###################################################
# load utils
. ./util/utils.sh
declare -A taskDic
declare -A taskStatus
# Wednesday execute task
taskWeek="3"
# task time config
taskDic=(
["10:51"]="./updateVersionFlow.sh"
["16:45"]="./updateVersionFlow.sh"
# ["21:56"]="./task1.sh"
# ["21:57"]="./task2.sh"
)
taskStatus=()
# init task status when it is set to true, means have excuted
function initTaskStatus {
for time in ${!taskDic[*]}
do
taskStatus[$time]="false"
done
}
function printTaskList {
echo
echoSuccess "----------------------------------"
echoError "Time | Task"
for key in ${!taskDic[*]}
do
echoSuccess "----------------------------------"
echoWarning "[$key] | ${taskDic[$key]}"
done
echoSuccess "----------------------------------"
}
# exec task
function executeTask {
while true
do
# set the cursor position
setCursor 0 0
currentWeek=$(date "+%w")
currentTime=$(date "+%H:%M")
displayTime=$(date "+%A %H:%M:%S")
echo
echoSuccess " $displayTime "
printTaskList
for time in ${!taskDic[*]}
do
if [ "${taskStatus[$time]}" = "false" ] &&
[ "$currentWeek" = "$taskWeek" ] &&
[ "$currentTime" = "$time" ]
then
taskStatus[$time]="true"
. ${taskDic["$time"]}
fi
# if has executed
if [ "${taskStatus[$time]}" = "true" ] &&
[ "$currentTime" != "$time" ]
then
taskStatus[$time]="false"
fi
done
done
}
function main {
# clear the screen
clear
# init taskStatus
initTaskStatus
# hide cursor
hideCursor
# excute task list
executeTask
}
main