-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget-rib.sh
69 lines (50 loc) · 1.66 KB
/
get-rib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Base URL for RouteViews archive
BASE_URL="http://archive.routeviews.org/bgpdata"
# Current working directory
RIB_DIR=$(pwd)
# Get yesterday's date in the format YYYY.MM and YYYYMMDD
YEAR_MONTH=$(date -d "yesterday" "+%Y.%m")
DAY=$(date -d "yesterday" "+%Y%m%d")
# Construct the URL for the previous day at 10:00
RIB_URL="$BASE_URL/$YEAR_MONTH/RIBS/rib.$DAY.1000.bz2"
# Hardcoded fallback URL
HARDCODED_URL="http://archive.routeviews.org/bgpdata/2023.08/RIBS/rib.20230807.1000.bz2"
# Filename to save the downloaded RIB
DOWNLOAD_PATH="$RIB_DIR/rib.$DAY.1000.bz2"
# Extracted RIB filename
EXTRACTED_RIB_FILE="$RIB_DIR/rib.$DAY.1000"
# Processed RIB filename
PROCESSED_RIB="$RIB_DIR/processed_rib.txt"
# Download the RIB file
echo "Downloading RIB data from $RIB_URL..."
curl -o $DOWNLOAD_PATH $RIB_URL
# Check if download was successful
if [ $? -ne 0 ]; then
echo "Failed to download RIB data from the generated URL."
echo "Falling back to hardcoded URL: $HARDCODED_URL..."
curl -o $DOWNLOAD_PATH $HARDCODED_URL
if [ $? -ne 0 ]; then
echo "Failed to download RIB data from hardcoded URL as well."
exit 1
fi
fi
echo "Extracting RIB data from $DOWNLOAD_PATH..."
# Decompress the RIB data
bunzip2 $DOWNLOAD_PATH
# Check if decompression was successful
if [ $? -ne 0 ]; then
echo "Failed to extract RIB data."
exit 1
fi
# Process the RIB data
echo "Processing RIB data with bgpdump..."
bgpdump $EXTRACTED_RIB_FILE > $PROCESSED_RIB
# Check if processing was successful
if [ $? -ne 0 ]; then
echo "Failed to process RIB data with bgpdump."
exit 1
fi
rm rib*
echo "RIB data processed and saved to $PROCESSED_RIB"
exit 0