Jianqing's Blog Archive

为了缓解学习压力,充分利用free time,开始学习各种命令,并尝试写一些很小的脚本

1.一个很无聊的脚本,其实只能算一个小命令

用来将arp文件中的IP解析出来,并排序显示出来

#!/bin/sh #this shell is used to show the arp infomation,and sort the IP echo “show the arp infomation,IP from 1–255” echo “******” cat /proc/net/arp | grep -v IP |cut -d “ “ -f1 | cut -d “.” -f4| sort -g echo “******”

2.无聊透顶!!~其实ping就已经可以实现了,呵呵,只是将那一大串信息简缩为一个“OK”

第一次写脚本,主要是实践,学习if ;then … fi的用法

#!/bin/sh #this shell is used to detect the network is Ok #and print some useful info. #ping 10.0.1.1 -c 4 >result.txt echo -n “please keyin the host:” read host #host=$1 result= ping $host -c 4 | grep transmitted | cut -d "," -f3 echo “result=$result” #if “$result”=” 0% packet loss” ; then if [ “$result” = “ 0% packet loss” ] ; then echo “the host:$host is OK” else echo “the host:$host is error” fi

Tags: