Created
December 30, 2012 01:12
-
-
Save opie4624/4410357 to your computer and use it in GitHub Desktop.
Calculate git-annex cost based on ping times for remote hosts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
PING="/sbin/ping" | |
PACKET_SIZE=64 | |
PACKET_COUNT=10 | |
PING_INTERVAL=1 | |
TIMEOUT=2 | |
BASE_COST=200 | |
HOST=$1 | |
# This one's for Max ping | |
PING_COST=`$PING -s $PACKET_SIZE -c $PACKET_COUNT -i $PING_INTERVAL -W $TIMEOUT $HOST | egrep "round-trip" | awk -F '/' '{print $6}'` | |
# This one's for Avg Ping | |
#PING_COST=`$PING -s $PACKET_SIZE -c $PACKET_COUNT -i $PING_INTERVAL -W $TIMEOUT $HOST | egrep "round-trip" | awk -F '/' '{print $5}'` | |
COST_INTEGER=`echo $PING_COST | awk -F '.' '{print $1}'` | |
let "COST = COST_INTEGER * 10 + BASE_COST" | |
#echo $PING_COST | |
#echo $COST_INTEGER | |
echo $COST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
PING="/sbin/ping6" | |
PACKET_SIZE=64 | |
PACKET_COUNT=10 | |
PING_INTERVAL=1 | |
TIMEOUT=2 | |
BASE_COST=200 | |
HOST=$1 | |
# This one's for Max ping | |
PING_COST=`$PING -s $PACKET_SIZE -c $PACKET_COUNT -i $PING_INTERVAL $HOST | egrep "round-trip" | awk -F '/' '{print $6}'` | |
# This one's for Avg Ping | |
#PING_COST=`$PING -s $PACKET_SIZE -c $PACKET_COUNT -i $PING_INTERVAL $HOST | egrep "round-trip" | awk -F '/' '{print $5}'` | |
COST_INTEGER=`echo $PING_COST | awk -F '.' '{print $1}'` | |
let "COST = COST_INTEGER * 10 + BASE_COST" | |
#echo $HOST | |
#echo $PING_COST | |
#echo $COST_INTEGER | |
echo $COST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment