From c8c9d4fa6ad225b6db6d58ce99fd83780076877b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Choch=C3=B3=C5=82?= Date: Fri, 15 Sep 2017 13:32:57 +0200 Subject: [PATCH] Implemented color diff, changed command compare to diff --- statesnap.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/statesnap.sh b/statesnap.sh index d151953..d6147ae 100755 --- a/statesnap.sh +++ b/statesnap.sh @@ -9,6 +9,10 @@ function msg() { echo -e "$BLUE * $GREEN$1$RST" } +function colorDiff { + awk '/^>/ { print "\033[31m"$0"\033[0m"; } /^]/ { print $0; }' +} + function makeSnap { FOLDER=~/server_states/state_$(date '+%Y%m%d_%H%M%S') mkdir -p $FOLDER @@ -26,27 +30,27 @@ function compare { msg "Comparing with snap $FOLDER" echo -e "$GREEN\nProcesses diff$RST" echo -e "$BLUE============================================================================$RST" - ps aux | awk '{ print $11 }' | sort | uniq | egrep -v '^\[' | diff - $FOLDER/ps.out + ps aux | awk '{ print $11 }' | sort | uniq | egrep -v '^\[' | diff - $FOLDER/ps.out | colorDiff echo -e "$GREEN\nOpened ports diff$RST" echo -e "$BLUE============================================================================$RST" - netstat -lpn | egrep "(tcp.*LISTEN|udp)" | sort | uniq | awk '{split($NF,arr,"/"); print $1 " " $4 " " arr[2]}' | diff - $FOLDER/netstat.out + netstat -lpn | egrep "(tcp.*LISTEN|udp)" | sort | uniq | awk '{split($NF,arr,"/"); print $1 " " $4 " " arr[2]}' | diff - $FOLDER/netstat.out | colorDiff echo -e "$GREEN\nFirewall rules diff$RST" echo -e "$BLUE============================================================================$RST" - (/sbin/iptables -L -n; echo -e "\n#NAT\n"; /sbin/iptables -L -nt nat) | diff - $FOLDER/iptables.out + (/sbin/iptables -L -n; echo -e "\n#NAT\n"; /sbin/iptables -L -nt nat) | diff - $FOLDER/iptables.out | colorDiff echo -e "$GREEN\nMounts diff$RST" echo -e "$BLUE============================================================================$RST" - mount | diff - $FOLDER/mount.out + mount | diff - $FOLDER/mount.out | colorDiff echo -e "$GREEN\nRouting table diff$RST" echo -e "$BLUE============================================================================$RST" - /sbin/ip route | diff - $FOLDER/routing.out + /sbin/ip route | diff - $FOLDER/routing.out | colorDiff } function printHelp { - echo -e "Server State 0.2b" + echo -e "State Snap 0.2b" echo -e "$BLUE============================================================================$RST" - echo -e "Użycie: $0 [PARAMETRY]...\n" - printf " $GREEN%-14s$RST %s\n" "snap" "- Make server status snapshot" - printf " $GREEN%-14s$RST %s\n\n" "compare" "- Make a diff comparison against latest snapshot" + echo -e "Use: $0 [PARAMETRS]...\n" + printf " $GREEN%-6s$RST %s\n" "snap" "- Make server status snapshot" + printf " $GREEN%-6s$RST %s\n\n" "diff" "- Make a diff comparison against latest snapshot" exit 0; } @@ -57,7 +61,7 @@ fi # główny kod case $1 in - compare) + diff) compare ;; snap)