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

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

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

  • November 22, 2011 at 6:11 pm
    Permalink

    It’s great to read something that’s both enjoyable and provides pramtgaisdc solutions.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.