-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathntimes
More file actions
executable file
·74 lines (62 loc) · 1.31 KB
/
Copy pathntimes
File metadata and controls
executable file
·74 lines (62 loc) · 1.31 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
fail_fast=false
times=0
interrupted=false
# Function to handle interrupt
handle_interrupt() {
echo -e "\nInterrupt received. Stopping execution."
interrupted=true
}
# Set up the interrupt trap
trap handle_interrupt SIGINT
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--fail-fast)
fail_fast=true
shift
;;
*)
if [[ $times -eq 0 ]]; then
times=$1
shift
else
break
fi
;;
esac
done
echo "Running command $@ $times times. (fail_fast=$fail_fast)"
successes=0
failures=0
for ((n=0; n < $times; n++)); do
if $interrupted; then
break
fi
"$@"
if [[ $? -eq 0 ]]; then
((successes++))
else
((failures++))
if [[ $fail_fast == true ]]; then
echo -e "\nFailed on iteration $((n+1)). Stopping execution."
break
fi
fi
echo -e "\nSuccesses: $successes"
echo -e "Failures: $failures\n"
done
if $interrupted; then
echo "Execution interrupted."
echo "Final results:"
echo -e "Successes: $successes"
echo -e "Failures: $failures\n"
echo "Exiting with status 130 (interrupt)."
exit 130 # Standard exit code for interrupt
elif [[ $failures == 0 ]]; then
echo "Exiting with status 0 (success)."
exit 0
else
echo "Exiting with status 1 (failure)."
exit 1
fi