Advertisement
quark_zju

Untitled

May 3rd, 2011
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.66 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. DATE_FILE=/tmp/.ssh.$1.date
  4. MAX_DIFF_TIME=16
  5.  
  6. while true; do
  7.     # ssh runner, note that ssh should be properly configured
  8.     # and should not ask for password
  9.     date +%s > $DATE_FILE
  10.     ssh $@ 'while sleep 1; do echo a; done' | while read i; do
  11.         date +%s > $DATE_FILE
  12.     done &
  13.  
  14.     # timeout monitor
  15.     while sleep 1; do
  16.         RECEIVED_TIME=`cat $DATE_FILE`
  17.         DIFF_TIME=$((`date +%s`-RECEIVED_TIME))
  18.         printf '\rDiff time: %d sec            \r' $DIFF_TIME
  19.         if [[ $DIFF_TIME -gt $MAX_DIFF_TIME ]] && [[ $RECEIVED_TIME -gt 1 ]]; then
  20.             printf "\nKilling jobs"
  21.             for i in `jobs -p`; do (kill $i; kill -9 $i;)&>/dev/null; done
  22.             break
  23.         fi
  24.     done
  25. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement