Implemented color diff, changed command compare to diff

master
Mateusz Chochół 8 years ago
parent 42f2001651
commit c8c9d4fa6a
  1. 24
      statesnap.sh

@ -9,6 +9,10 @@ function msg() {
echo -e "$BLUE * $GREEN$1$RST" echo -e "$BLUE * $GREEN$1$RST"
} }
function colorDiff {
awk '/^>/ { print "\033[31m"$0"\033[0m"; } /^</ { print "\033[32m"$0"\033[0m"; } /^[^<>]/ { print $0; }'
}
function makeSnap { function makeSnap {
FOLDER=~/server_states/state_$(date '+%Y%m%d_%H%M%S') FOLDER=~/server_states/state_$(date '+%Y%m%d_%H%M%S')
mkdir -p $FOLDER mkdir -p $FOLDER
@ -26,27 +30,27 @@ function compare {
msg "Comparing with snap $FOLDER" msg "Comparing with snap $FOLDER"
echo -e "$GREEN\nProcesses diff$RST" echo -e "$GREEN\nProcesses diff$RST"
echo -e "$BLUE============================================================================$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 "$GREEN\nOpened ports diff$RST"
echo -e "$BLUE============================================================================$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 "$GREEN\nFirewall rules diff$RST"
echo -e "$BLUE============================================================================$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 "$GREEN\nMounts diff$RST"
echo -e "$BLUE============================================================================$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 "$GREEN\nRouting table diff$RST"
echo -e "$BLUE============================================================================$RST" echo -e "$BLUE============================================================================$RST"
/sbin/ip route | diff - $FOLDER/routing.out /sbin/ip route | diff - $FOLDER/routing.out | colorDiff
} }
function printHelp { function printHelp {
echo -e "Server State 0.2b" echo -e "State Snap 0.2b"
echo -e "$BLUE============================================================================$RST" echo -e "$BLUE============================================================================$RST"
echo -e "Użycie: $0 [PARAMETRY]...\n" echo -e "Use: $0 [PARAMETRS]...\n"
printf " $GREEN%-14s$RST %s\n" "snap" "- Make server status snapshot" printf " $GREEN%-6s$RST %s\n" "snap" "- Make server status snapshot"
printf " $GREEN%-14s$RST %s\n\n" "compare" "- Make a diff comparison against latest snapshot" printf " $GREEN%-6s$RST %s\n\n" "diff" "- Make a diff comparison against latest snapshot"
exit 0; exit 0;
} }
@ -57,7 +61,7 @@ fi
# główny kod # główny kod
case $1 in case $1 in
compare) diff)
compare compare
;; ;;
snap) snap)

Loading…
Cancel
Save