05 - Script
1) Script d'administration Bash
Ce script centralise les opérations courantes d'administration de l'infrastructure VoIP.
##############################################################
# Auteur : mkermorvant #
# Date de modification : 2026031920260511 #
# #
# Description : ScriptManagement de migration de conteneur lxcAsterisk #
# #
##############################################################
#! /bin/bash #
# #
##############################################################
# Variables :
echo"echo ""
ASTERISK_IP=ASTERISK="192.168.10.69"99.9"
TEL_1000="192.168.10.67"
TEL_1001="192.168.10.66"
VERT='\033[0;32m'
ROUGE='\033[0;31m'
JAUNE='\033[0;33m'
NEUTRE='\033[0m'
BLEU='\033[0;36m'
PS3="Qu'elle action souhaiter vous exécuter : "
OPTIONS=( "Statut Serveur Asterisk" "Ping" "Contacts" "Appels en cours" "Redémarrage Serveur Assterisk" "Rechargement Config" "Quitter" )
##############################################################
casewhile true; do
clear
echo -e "$1" in
status){BLEU}###############################################################"
echo "# #"
echo "# Admin Asterisk #"
echo "# #"
echo "###############################################################"
echo "# #"
echo "# Liste Options : #"
echo "# #"
echo "# 1) Statut Serveur #"
echo "# 2) Ping Téléphones #"
echo "# 3) Liste Contacts #"
echo "# 4) Liste Appel #"
echo "# 5) Redémarage Asterisk #"
echo "# 6) Rechargement Config #"
echo "# 7) Quitter #"
echo "# #"
echo -e "###############################################################${NEUTRE}"
##############################################################
echo -ne " Votre choix : "
read REPLY
case $REPLY in
1)
echo -e "${VERT}=== Statut du service ==="
systemctl status asterisk --no-pager
;;
restart)
echo "=== RedémarrageServeur Asterisk ===${NEUTRE}"
sudo systemctl restartstatus asteriskasterisk.service
echo "Attente 5s..." && sleep 5
sudo asterisk -rx "pjsip show contacts"
;;
contacts)2)
echo -e "${VERT}=== EnregistrementsPing SIPAsterisk ==="vers sudo asterisk -rx "pjsip show contacts"
;;
calls)
echo "=== Appels en cours ==="
sudo asterisk -rx "core show channels"
;;
port)
echo "=== Port 5160 ==="
ss -ulnp | grep 5160
;;
ping)
echo "=== Test connectivité téTéléphones ===${NEUTRE}"
ping -c 3 $TEL_1000 && echo -e "${VERT}1000 OK"OK${NEUTRE}" ||echo -e "${VERT}1000 KO${NEUTRE}"
echo "1000 KO""
ping -c 3 $TEL_1001 && echo -e "${VERT}1001 OK"OK${NEUTRE}" ||echo -e "${ROUGE}1001 KO${NEUTRE}"
echo "1001 KO""
;;
reload)3)
echo -e "${VERT}=== Liste contacts Asterisk ===${NEUTRE}"
sudo asterisk -rx "pjsip show contacts"
echo""
;;
4)
echo -e "${VERT}=== Liste d'appel en cours ===${NEUTRE}"
sudo asterisk -rx "core show channels"
echo ""
;;
5)
echo -e "${VERT}=== Redémarage du Serveur Asterisk ===${NEUTRE}"
sudo systemctl restart asterisk.service
echo ""
;;
6)
echo -e "${VERT}=== Rechargement configde la Configuration ===${NEUTRE}"
sudo asterisk -rx "module reload res_pjsip.so"
sudo asterisk -rx "dialplan reload"
echo ""
;;
logs)7)
echo -e "${JAUNE}=== Quitter ===${NEUTRE}"
break
echo "=== Logs Asterisk (Ctrl+C pour quitter) ==="
sudo tail -f /var/log/asterisk/full
;;
health)
echo "=== Health Check Complet ==="
systemctl is-active asterisk && echo "Service: OK" || echo "Service: KO"
ss -ulnp | grep -q 5160 && echo "Port 5160: OK" || echo "Port 5160: KO"
ping -c 1 -W 1 $TEL_1000 > /dev/null && echo "Tel 1000: OK" || echo "Tel 1000: KO"
ping -c 1 -W 1 $TEL_1001 > /dev/null && echo "Tel 1001: OK" || echo "Tel 1001: KO"
;;
*)
echo -e "Usage:${ROUGE}=== Option invalide, veuillez réessayer ===$0{NEUTRE}"
{status|restart|contacts|calls|port|ping|reload|logs|health}echo ""
;;
esac
echo -ne "Appuie sur Entrée..."
read
done