免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2045 | 回复: 3
打印 上一主题 下一主题

帮看看这个shell [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-11-14 18:00 |只看该作者 |倒序浏览
请教大家几个问题:
1.getmac()里面的这两行是什么意思:
    ethhw=$(ifconfig $1 | grep HWaddr)
      ethhw=${ethhw##*HWaddr }
2.getcpu()里面的这行是什么意思:
    "$cpuinfo" >> $1
3.getdisk()里面的这行是什么意思:
    diskinfo=${diskinfo##*SerialNo=}

先谢过啦!脚本见下面:




  



-------------------------------------shell-------------------------------------
getmac()
{
  ethhw=$(ifconfig $1 | grep HWaddr)   
  if [ "$ethhw" != "" ];
  then
  ethhw=${ethhw##*HWaddr }
  echo "$1 $ethhw" >> $2
  fi
}

getcpu()
{
  cpuinfo=$(grep "model name"  /proc/cpuinfo)
  echo "$cpuinfo" >> $1
}

getdisk()
{
  diskinfo=$(hdparm -i /dev/$1 | grep SerialNo)
  if [ "$diskinfo" != "" ];
  then
    diskinfo=${diskinfo##*SerialNo=}
    echo "$1 $diskinfo" >> $2
  fi
}

case $1 in
  -f)
   true > $2
   case $3 in
     -mac)
      getmac eth0 $2
     ;;
     -disk)
      getdisk hda $2
      getdisk hdb $2
      getdisk hdc $2
      getdisk hdd $2
      getdisk hde $2
      getdisk hdf $2
      getdisk sda $2
      getdisk sdb $2
      getdisk sdc $2
      getdisk sdd $2
      getdisk sde $2
      getdisk sdf $2
     ;;
     -cpu)
      getcpu $2
     ;;
     *)
      getcpu $2
      getmac eth0 $2
      getmac eth1 $2
      getmac eth2 $2
      getmac eth3 $2
      getmac eth4 $2
      getmac eth5 $2
      getmac eth6 $2
      getmac eth7 $2
      getdisk hda $2
      getdisk hdb $2
      getdisk hdc $2
      getdisk hdd $2
      getdisk hde $2
      getdisk hdf $2
      getdisk sda $2
      getdisk sdb $2
      getdisk sdc $2
      getdisk sdd $2
      getdisk sde $2
      getdisk sdf $2
   ;;
   esac
   ;;
*)
  ;;
esac

论坛徽章:
0
2 [报告]
发表于 2011-11-14 22:47 |只看该作者
本帖最后由 zcheung 于 2011-11-14 22:53 编辑

$1 的意思为 第一个参数 等同 argv[0]
>> 这个不懂看下书吧。

你所打的
  1. ethhw=${ethhw##*HWaddr }
复制代码
从变量ethhw的开头, 删除最长匹配HWaddr的子串

你确定没有打错?
应该是
  1. ethhw=${ethhw##HWaddr }[
复制代码

论坛徽章:
0
3 [报告]
发表于 2011-11-15 14:42 |只看该作者
就是分别提取出 mac地址,cpu型号,以及硬盘序列号

论坛徽章:
0
4 [报告]
发表于 2011-11-15 15:00 |只看该作者
赋值变量。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP