Refactorying horizontal line printing

master
Mateusz Chochół 8 years ago
parent 56ba367869
commit 999a539181
  1. 22
      statesnap.sh

@ -13,6 +13,10 @@ function colorDiff {
awk '/^>/ { print "\033[31m"$0"\033[0m"; } /^</ { print "\033[32m"$0"\033[0m"; } /^[^<>]/ { print $0; }' awk '/^>/ { print "\033[31m"$0"\033[0m"; } /^</ { print "\033[32m"$0"\033[0m"; } /^[^<>]/ { print $0; }'
} }
function HL {
echo -e "$BLUE============================================================================$RST"
}
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
@ -28,26 +32,20 @@ function makeSnap {
function compare { function compare {
FOLDER=~/server_states/$(ls ~/server_states/ | tail -n 1) FOLDER=~/server_states/$(ls ~/server_states/ | tail -n 1)
msg "Comparing with snap $FOLDER" msg "Comparing with snap $FOLDER"
echo -e "$GREEN\nProcesses diff$RST" echo -e "$GREEN\nProcesses diff$RST"; HL
echo -e "$BLUE============================================================================$RST"
ps aux | awk '{ print $11 }' | sort | uniq | egrep -v '^\[' | diff - $FOLDER/ps.out | colorDiff 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"; HL
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 | colorDiff 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"; HL
echo -e "$BLUE============================================================================$RST"
(/sbin/iptables -L -n; echo -e "\n#NAT\n"; /sbin/iptables -L -nt nat) | diff - $FOLDER/iptables.out | colorDiff (/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"; HL
echo -e "$BLUE============================================================================$RST"
mount | diff - $FOLDER/mount.out | colorDiff mount | diff - $FOLDER/mount.out | colorDiff
echo -e "$GREEN\nRouting table diff$RST" echo -e "$GREEN\nRouting table diff$RST"; HL
echo -e "$BLUE============================================================================$RST"
/sbin/ip route | diff - $FOLDER/routing.out | colorDiff /sbin/ip route | diff - $FOLDER/routing.out | colorDiff
} }
function printHelp { function printHelp {
echo -e "State Snap 0.2b" echo -e "State Snap 0.2b"; HL
echo -e "$BLUE============================================================================$RST"
echo -e "Use: $0 [PARAMETRS]...\n" echo -e "Use: $0 [PARAMETRS]...\n"
printf " $GREEN%-6s$RST %s\n" "snap" "- Make server status snapshot" 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" printf " $GREEN%-6s$RST %s\n\n" "diff" "- Make a diff comparison against latest snapshot"

Loading…
Cancel
Save