-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopTaskWithDelay.sh
More file actions
47 lines (32 loc) · 1.01 KB
/
Copy pathLoopTaskWithDelay.sh
File metadata and controls
47 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
###################### HELP HEADER #################################
function display_help() {
echo "Usage: $0 <Task.sh> [wait_time] [max_executions]"
echo -e "\nParameters:"
echo " Task.sh: Path to the Task.sh File"
echo " wait_time: Time to wait between executions. Default 0 seconds."
echo " max_executions: Maximum number of times to execute the command. Default infinite loop."
echo -e "\nExample:"
echo "Usage: $0 ./Task.sh 10 4"
exit 1
}
if [[ "$1" == "-h" || "$1" == "-help" || "$1" == "--help" ]]; then
display_help
fi
###################### CODE #########################################
if [ -z "$1" ]; then
echo "Please specify the executable path."
exit 1
fi
WAIT_TIME=${2:-0}
MAX_EXECUTIONS=${3:-0}
if [ ! -x "$1" ]; then
echo "File not executable or not found."
exit 1
fi
EXECUTION_COUNT=0
while [[ 0 == $MAX_EXECUTIONS ]] || [[ $EXECUTION_COUNT < $MAX_EXECUTIONS ]]; do
"$1"
echo "Executed. Waiting $WAIT_TIME seconds..."
sleep $WAIT_TIME
((EXECUTION_COUNT++))
done