Skip to content

Instantly share code, notes, and snippets.

@opie4624
Created December 30, 2012 01:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opie4624/4410357 to your computer and use it in GitHub Desktop.
Save opie4624/4410357 to your computer and use it in GitHub Desktop.
Calculate git-annex cost based on ping times for remote hosts.
#!/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
#!/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