2009. december 9., szerda

Colorized online/offline checker in bash

Kora reggeli agymenés....


 #!/bin/bash
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
txtred=$(tput setaf 1) # Red
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
HOST=IP_ADDRESS
ERTEK=`ping -q -c 4 $HOST | grep "round-trip" |sed 's/\// /g' | awk '{print $8}' | awk '{printf("%d\n",$1 + 0.5);}'`
if [ "$ERTEK" = "" ]; then
ERTEK=-1
fi
if [ $ERTEK -ge 0 ]; then
echo "${txtgrn}online${txtrst}"
else
echo "${txtred}offline${txtrst}"
fi

Nincsenek megjegyzések: