Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout option for script command #79

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config-example
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ MY_TIMEOUT="2"
MY_PING_TIMEOUT="4"
MY_PING_COUNT="2"

# Duration we wait for response (only script).
MY_SCRIPT_TIMEOUT="20"

# Route to host
MY_TRACEROUTE_HOST="1.1.1.1" # Cloudflare DNS
# Sets the number of probe packets per hop
Expand Down
6 changes: 5 additions & 1 deletion status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ MY_TIMEOUT=${MY_TIMEOUT:-"2"}
MY_PING_TIMEOUT=${MY_PING_TIMEOUT:-"4"}
MY_PING_COUNT=${MY_PING_COUNT:-"2"}

# Duration we wait for response (only script)
MY_SCRIPT_TIMEOUT=${MY_SCRIPT_TIMEOUT:-20}

# Route to host
MY_TRACEROUTE_HOST=${MY_TRACEROUTE_HOST:-"1.1.1.1"} # Cloudflare DNS
# Sets the number of probe packets per hop
Expand Down Expand Up @@ -210,6 +213,7 @@ debug_variables() {
echo "MY_TIMEOUT: $MY_TIMEOUT"
echo "MY_PING_TIMEOUT: $MY_PING_TIMEOUT"
echo "MY_PING_COUNT: $MY_PING_COUNT"
echo "MY_SCRIPT_TIMEOUT: $MY_SCRIPT_TIMEOUT"
echo "MY_TRACEROUTE_HOST: $MY_TRACEROUTE_HOST"
echo "MY_TRACEROUTE_NQUERIES: $MY_TRACEROUTE_NQUERIES"
echo
Expand Down Expand Up @@ -911,7 +915,7 @@ while IFS=';' read -r MY_COMMAND MY_HOSTNAME_STRING MY_PORT || [[ -n "$MY_COMMAN
else
cmd="$MY_HOSTNAME"
fi
($cmd &> /dev/null)
(timeout "$MY_SCRIPT_TIMEOUT" "$cmd" &> /dev/null)
case "$?" in
"0")
check_downtime "$MY_COMMAND" "$MY_HOSTNAME_STRING" "$MY_PORT"
Expand Down