Skip to main content

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 : 20260319                            #
#                                                            #
# Description : Script de migration de conteneur lxc         #
#                                                            #
##############################################################
#! /bin/bash                                                 #
#                                                            #
##############################################################

ASTERISK_IP="192.168.10.69"
TEL_1000="192.168.10.67"
TEL_1001="192.168.10.66"

case "$1" in
  status)
    echo "=== Statut du service ==="
    systemctl status asterisk --no-pager
    ;;
  restart)
    echo "=== Redémarrage Asterisk ==="
    sudo systemctl restart asterisk
    echo "Attente 5s..." && sleep 5
    sudo asterisk -rx "pjsip show contacts"
    ;;
  contacts)
    echo "=== Enregistrements SIP ==="
    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éléphones ==="
    ping -c 3 $TEL_1000 && echo "1000 OK" || echo "1000 KO"
    ping -c 3 $TEL_1001 && echo "1001 OK" || echo "1001 KO"
    ;;
  reload)
    echo "=== Rechargement config ==="
    sudo asterisk -rx "module reload res_pjsip.so"
    sudo asterisk -rx "dialplan reload"
    ;;
  logs)
    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 "Usage: $0 {status|restart|contacts|calls|port|ping|reload|logs|health}"
    ;;
esac