Skip to content

Instantly share code, notes, and snippets.

@andrius
Last active October 27, 2019 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrius/528c86fa7c865829fd64366faf1603d3 to your computer and use it in GitHub Desktop.
Save andrius/528c86fa7c865829fd64366faf1603d3 to your computer and use it in GitHub Desktop.
Script to terminate Asterisk PBX calls after the timeout

Initial steps:

Following command will print out details of all active calls:

asterisk -rx "core show channels concise"
# Output:
# SIP/alice-00000002!asterisk.cr!!1!Up!Echo!!!!!3!77!!1572188916.4

Cound delimiters '!' for your asterisk and test with command below, it prints channel name and duration:

asterisk -rx "core show channels concise" | awk -F '!' '{print $1" "$12}'
# Output:
# SIP/alice-00000002 167

Finally the script it will print out asterisk command to hangup call or call duration. Output it to the temp file and execute it, that's all

asterisk -rx "core show channels concise" | awk -F '!' '{print ($12 > 300) ? "asterisk -rx \"hangup request "$1"\"" : "echo \""$1" "$12"\"" }'

# Output:
# asterisk -rx "hangup request SIP/alice-00000002"
asterisk -rx "core show channels concise" | awk -F '!' '{print ($12 > 3000) ? "asterisk -rx \"hangup request "$1"\"" : "echo \""$1" "$12"\"" }'
# Output:
# echo "SIP/alice-00000002 476"

How to use script:

asterisk -rx "core show channels concise" | awk -F '!' '{print ($12 > 300) ? "asterisk -rx \"hangup request "$1"\"" : "echo \""$1" "$12"\"" }' \
> /tmp/tempfile.sh && sh -c /tmp/tempfile.sh; rm /tmp/tempfile.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment