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.
|
|
|
name="$(ifconfig | awk -F- '$2 ~ /eth/ { print $1; exit;}')"
|
|
|
|
|
|
|
|
log_directory=$HOME/logs/
|
|
|
|
log_file=${name}-rt.log
|
|
|
|
|
|
|
|
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
case $1 in
|
|
|
|
-c|--cmd)
|
|
|
|
RT_COMMAND="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
-o|--output)
|
|
|
|
OUTPUT_FILE="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
-*|--*)
|
|
|
|
echo "Unknown option $1"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
: "${RT_COMMAND:='route -n'}"
|
|
|
|
: "${OUTPUT_FILE:=${log_directory}${log_file}}"
|
|
|
|
|
|
|
|
echo "COMMAND: $RT_COMMAND"
|
|
|
|
echo "OUTPUT: $OUTPUT_FILE"
|
|
|
|
|
|
|
|
echo > "$OUTPUT_FILE"
|
|
|
|
echo "starting at: $(date +"%T %N")" >> "$OUTPUT_FILE"
|
|
|
|
|
|
|
|
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 "here"
|
|
|
|
echo -e "$(date +"%T %N")\t$2\t$line" >> "$OUTPUT_FILE"
|
|
|
|
done <<< "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
curr=$($RT_COMMAND)
|
|
|
|
atstart="$(echo "$curr" | sed '1,2d')"
|
|
|
|
log "$atstart" "add:"
|
|
|
|
|
|
|
|
|
|
|
|
while true;
|
|
|
|
do
|
|
|
|
prev="$curr"
|
|
|
|
curr=$($RT_COMMAND)
|
|
|
|
|
|
|
|
diff_out=$(diff -u <(echo "$prev") <(echo "$curr"))
|
|
|
|
[ $? -eq 0 ] || parse_diff "$diff_out"
|
|
|
|
sleep 0.5
|
|
|
|
|
|
|
|
done
|