NETWORK ENGINEER BLOG

Tips and Reviews for Engineers

便利なスクリプト(CentOS)

Ping を実行した際、Windows のように"Request Timed out"を表示させる。

[root@hostname ~]# host=***.***.***.***; max_cnt=10; cnt=0; while [ $cnt -le $max_cnt ]; do rslt=`ping -w 1 -c 1 $host | grep 'bytes from '`; if [ $? -gt 0 ]; then echo -e "`date +'%H:%M:%S'` $host Request timed out."; else echo "`date +'%H:%M:%S'` $host`echo $rslt | cut -d  ':' -f 2`"; sleep 1; fi; cnt=$(expr $cnt + 1); done;

任意のコマンド(例:df -h)を 5秒間隔で繰り返し実行する。

[username@hostname]$ while true; do date; df -h; sleep 5; clear; done;

参考:http://sonic64.com/2004-05-28.html

以上