imac2を常用して、待機させているimacを使うとき、Wake On Lanが便利そうで、疎通したのが良くわかるように下記の<wol.sh>を書いた。
% wol.sh .... 使用例
(0) 06:58:15 Request timeout for icmp_seq 0
(1) 06:58:17 Request timeout for icmp_seq 0
(2) 06:58:19 Request timeout for icmp_seq 0
(3) 06:58:21 64 bytes from 192.168.1.51: icmp_seq=1 ttl=64 time=0.649 ms
imac is alive.
%
<wol.sh>
#! /bin/zsh
PHOST=imac
PWMAC="D4:9A:20:xx:xx:xx"
CUR=0
echo -n "($CUR) `date "+%H:%M:%S"` "
PLINE=`ping -t 2 -c 2 $PHOST 2&>1 |egrep '^64|^Req|down'|tail -1`
echo $PLINE
WORD1=`echo $PLINE |awk '{print $1}'`
if [ "${WORD1}" = "64" ]; then
echo "$PHOST is alive."
exit 0
fi
# Wake-On-Lan
# http://www.gcd.org/sengoku/docs/wol.c
/usr/local/bin/wol 192.168.1.255 $PWMAC
while (true)
do
CUR=`expr $CUR + 1`
echo -n "($CUR) `date "+%H:%M:%S"` "
PLINE=`ping -t 2 -c 2 $PHOST 2&>1 |egrep '^64|^Req|down'|tail -1`
echo $PLINE
WORD1=`echo $PLINE |awk '{print $1}'`
if [ "${WORD1}" = "64" ]; then
echo "$PHOST is alive."
exit 0
fi
done
exit 0

0 件のコメント:
コメントを投稿