Non-Interactive Mode
Execute CLI commands from scripts and automation tools.
Overview
Non-interactive mode allows you to execute a single CLI command without entering the interactive shell:
/opt/athena-bng/bin/abng -c "show subscribers"
/opt/athena-bng/bin/abng -c "show system"
This is useful for:
- Scripting and automation
- Integration with monitoring systems
- Cron jobs and scheduled tasks
- Integration with third-party tools
Basic Usage
Execute a Single Command
/opt/athena-bng/bin/abng -c "show subscribers"
Execute with Custom Socket
/opt/athena-bng/bin/abng -s /opt/athena-bng/run/abngd.sock -c "show system"
Capture Output
OUTPUT=$(/opt/athena-bng/bin/abng -c "show subscribers")
echo "$OUTPUT"
Examples
Get Session Count
#!/bin/bash
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
echo "Active sessions: $COUNT"
Get PPPoE and DHCP Counts
#!/bin/bash
PPPOE=$(/opt/athena-bng/bin/abng -c "show subscribers pppoe | count" | grep -oP '\d+')
DHCP=$(/opt/athena-bng/bin/abng -c "show subscribers dhcp | count" | grep -oP '\d+')
echo "PPPoE: $PPPOE, DHCP: $DHCP"
Monitor Session Count
#!/bin/bash
while true; do
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$TIMESTAMP] Sessions: $COUNT"
sleep 60
done
Export Configuration
#!/bin/bash
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
/opt/athena-bng/bin/abng -c "show configuration | save /tmp/config-$TIMESTAMP.yaml"
echo "Configuration exported to /tmp/config-$TIMESTAMP.yaml"
Disconnect a Session
#!/bin/bash
SESSION_ID=$1
if [ -z "$SESSION_ID" ]; then
echo "Usage: $0 <session_id>"
exit 1
fi
/opt/athena-bng/bin/abng -c "request subscriber disconnect $SESSION_ID"
Usage:
./disconnect.sh 1
Cron Jobs
Hourly Session Report
#!/bin/bash
# /opt/athena-bng/bin/session-report.sh
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
PPPOE=$(/opt/athena-bng/bin/abng -c "show subscribers pppoe | count" | grep -oP '\d+')
DHCP=$(/opt/athena-bng/bin/abng -c "show subscribers dhcp | count" | grep -oP '\d+')
echo "[$TIMESTAMP] Total: $COUNT, PPPoE: $PPPOE, DHCP: $DHCP" >> /var/log/session-report.log
Add to crontab:
0 * * * * /opt/athena-bng/bin/session-report.sh
Daily Configuration Backup
#!/bin/bash
# /opt/athena-bng/bin/backup-config.sh
BACKUP_DIR=/opt/athena-bng/etc/backups
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
mkdir -p "$BACKUP_DIR"
/opt/athena-bng/bin/abng -c "show configuration | save $BACKUP_DIR/config-$TIMESTAMP.yaml"
# Keep only last 30 days
find "$BACKUP_DIR" -name "config-*.yaml" -mtime +30 -delete
Add to crontab:
0 2 * * * /opt/athena-bng/bin/backup-config.sh
Integration with Monitoring Systems
Prometheus Exporter
#!/bin/bash
# /opt/athena-bng/bin/prometheus-exporter.sh
PORT=9100
LISTEN="0.0.0.0:$PORT"
while true; do
{
echo "HTTP/1.1 200 OK"
echo "Content-Type: text/plain"
echo ""
# Get metrics
TOTAL=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
PPPOE=$(/opt/athena-bng/bin/abng -c "show subscribers pppoe | count" | grep -oP '\d+')
DHCP=$(/opt/athena-bng/bin/abng -c "show subscribers dhcp | count" | grep -oP '\d+')
# Output Prometheus format
echo "# HELP athenabng_sessions_total Total active sessions"
echo "# TYPE athenabng_sessions_total gauge"
echo "athenabng_sessions_total $TOTAL"
echo "# HELP athenabng_sessions_pppoe PPPoE sessions"
echo "# TYPE athenabng_sessions_pppoe gauge"
echo "athenabng_sessions_pppoe $PPPOE"
echo "# HELP athenabng_sessions_dhcp DHCP sessions"
echo "# TYPE athenabng_sessions_dhcp gauge"
echo "athenabng_sessions_dhcp $DHCP"
} | nc -l -p $PORT -q 1
done
Nagios/Icinga Check
#!/bin/bash
# /opt/athena-bng/bin/check-sessions.sh
WARN_THRESHOLD=1000
CRIT_THRESHOLD=5000
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
if [ "$COUNT" -ge "$CRIT_THRESHOLD" ]; then
echo "CRITICAL: $COUNT sessions (threshold: $CRIT_THRESHOLD)"
exit 2
elif [ "$COUNT" -ge "$WARN_THRESHOLD" ]; then
echo "WARNING: $COUNT sessions (threshold: $WARN_THRESHOLD)"
exit 1
else
echo "OK: $COUNT sessions"
exit 0
fi
Error Handling
Check if abngd is Running
#!/bin/bash
if ! /opt/athena-bng/bin/abng -c "show version" > /dev/null 2>&1; then
echo "Error: abngd is not running"
exit 1
fi
Retry Logic
#!/bin/bash
MAX_RETRIES=5
RETRY_DELAY=2
for i in $(seq 1 $MAX_RETRIES); do
if /opt/athena-bng/bin/abng -c "show version" > /dev/null 2>&1; then
echo "Connected to abngd"
break
fi
if [ $i -lt $MAX_RETRIES ]; then
echo "Retry $i/$MAX_RETRIES, waiting ${RETRY_DELAY}s..."
sleep $RETRY_DELAY
else
echo "Error: Could not connect to abngd after $MAX_RETRIES retries"
exit 1
fi
done
Tips and Tricks
Parse JSON Output
#!/bin/bash
# Get session count from JSON output
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers" | jq '.[] | length')
echo "Sessions: $COUNT"
Combine Multiple Commands
#!/bin/bash
# Get system info and session count
SYSTEM=$(/opt/athena-bng/bin/abng -c "show system")
SESSIONS=$(/opt/athena-bng/bin/abng -c "show subscribers | count")
echo "System Info:"
echo "$SYSTEM"
echo ""
echo "Sessions:"
echo "$SESSIONS"
Conditional Logic
#!/bin/bash
# Disconnect if too many sessions
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count" | grep -oP '\d+')
if [ "$COUNT" -gt 5000 ]; then
echo "Too many sessions ($COUNT), disconnecting oldest..."
# Implement logic to disconnect oldest sessions
fi
Performance Considerations
Minimize Command Calls
# Bad: Multiple calls
COUNT=$(/opt/athena-bng/bin/abng -c "show subscribers | count")
PPPOE=$(/opt/athena-bng/bin/abng -c "show subscribers pppoe | count")
DHCP=$(/opt/athena-bng/bin/abng -c "show subscribers dhcp | count")
# Better: Single call with filtering
OUTPUT=$(/opt/athena-bng/bin/abng -c "show subscribers")
COUNT=$(echo "$OUTPUT" | grep -c "^│")
PPPOE=$(echo "$OUTPUT" | grep -c "PPPoE")
DHCP=$(echo "$OUTPUT" | grep -c "DHCP")
Cache Results
#!/bin/bash
CACHE_FILE=/tmp/abng-cache.txt
CACHE_TTL=60
if [ -f "$CACHE_FILE" ] && [ $(($(date +%s) - $(stat -f%m "$CACHE_FILE"))) -lt $CACHE_TTL ]; then
cat "$CACHE_FILE"
else
/opt/athena-bng/bin/abng -c "show subscribers" | tee "$CACHE_FILE"
fi
Next Steps
- Operational Mode — All
showandrequestcommands - Configuration Mode — All
set,delete,commitcommands