You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
863 B
Bash
39 lines
863 B
Bash
name="$(ifconfig | awk -F- '$2 ~ /eth/ { print $1; exit;}')"
|
|
log_directory="./logs/"
|
|
log_file="${name}_routingtable.log"
|
|
log_path="${log_directory}${log_file}"
|
|
|
|
echo > "$log_path"
|
|
|
|
function parse_diff () {
|
|
|
|
str=$(echo "$1" | sed '1,5d')
|
|
|
|
add_line=$(echo "$str" | grep -E '^\+')
|
|
rem_line=$(echo "$str" | grep -E '^-')
|
|
|
|
[ -n "$rem_line" ] && log "$(echo "$rem_line" | cut -c 2-)" "del:"
|
|
[ -n "$add_line" ] && log "$(echo "$add_line" | cut -c 2-)" "add:"
|
|
}
|
|
|
|
function log () {
|
|
while IFS= read -r line; do
|
|
echo -e "$(date +"%Y-%m-%d_%H-%M-%S")\t$2\t$line" >> ${log_path}
|
|
done <<< "$1"
|
|
}
|
|
|
|
|
|
curr=$(route -n)
|
|
atstart="$(echo "$curr" | sed '1,2d')"
|
|
log "$atstart" "add:"
|
|
|
|
|
|
while true;
|
|
do
|
|
prev="$curr"
|
|
curr=$(route -n)
|
|
|
|
diff_out=$(diff -u <(echo "$prev") <(echo "$curr"))
|
|
[ $? -eq 0 ] || parse_diff "$diff_out"
|
|
done
|