Files
bgp-server/update-prefixes.sh
2025-07-11 18:46:16 +07:00

39 lines
1.3 KiB
Bash

#!/bin/bash
# Bash script to update BGP prefixes on Linux
# BGP Prefixes Update Script
PREFIXES_FILE=${1:-"prefixes.txt"}
echo -e "\033[36mUpdating BGP Prefixes...\033[0m"
# Check if container is running
container_status=$(docker ps --filter "name=bgp-server" --format "{{.Names}}")
if [ -z "$container_status" ]; then
echo -e "\033[31mError: BGP container is not running. Please start it first.\033[0m"
echo -e "\033[33mRun: ./start-bgp-server.sh\033[0m"
exit 1
fi
# Check if prefixes file exists
if [ ! -f "$PREFIXES_FILE" ]; then
echo -e "\033[31mError: Prefixes file '$PREFIXES_FILE' not found.\033[0m"
exit 1
fi
# Copy new prefixes file to container
echo -e "\033[33mCopying new prefixes file to container...\033[0m"
docker cp "$PREFIXES_FILE" bgp-server:/etc/frr/prefixes.txt
# Reload BGP configuration
echo -e "\033[33mReloading BGP configuration...\033[0m"
docker exec bgp-server vtysh -c "configure terminal" -c "router bgp 65000" -c "clear ip bgp *" -c "end"
# Wait a moment for BGP to stabilize
sleep 3
# Show updated BGP table
echo -e "\n\033[32mUpdated BGP table:\033[0m"
docker exec bgp-server vtysh -c "show ip bgp"
echo -e "\n\033[32mPrefixes updated successfully!\033[0m"
echo -e "\033[33mTo view current prefixes: docker exec -it bgp-server vtysh -c 'show ip bgp'\033[0m"