菜蜂 发表于 2018-8-21 11:24:37

shell知识

for:  for VAR in LIST
  do
  COMMANDS
  done
  LIST的写法:
  直接写:for i in 1 2 3
  大括号扩展:for i in {0..99}
  通配符:for i in /etc/*.conf
  命令的结果:for i in `find /etc/ -name "*.conf"`
  C风格:for ((i=0;i /dev/null
  if [ "$?" == "0" ] ; then
  echo "192.168.18.$i online."
  else
  echo "192.168.18.$i offline."
  fi
  done
  方法二:
  for i in {252..254} ; do
  if ping -c1 192.168.18.$i &> /dev/null ; then
  echo "192.168.18.$i online."
  else
  echo "192.168.18.$i offline."
  fi
  done
  方法三:
  for i in {252..254} ; do
  result=`ping -c1 192.168.18.$i | grep ttl | cut -d "=" -f 2 | cut -d " " -f 2`
  if [ "$result" == "ttl" ] ; then
  echo "192.168.18.$i online."
  else
  echo "192.168.18.$i offline."
  fi
  done
  mssh.sh
  #!/bin/bash
  #mssh.sh "IP1 IP2""service iptables stop"
  for i in $1 ; do
  ssh $i $2
  done
  监控磁盘
  #!/bin/bash
  for space in `LANG=C df -h | grep -v Use | awk '{print $5}' | cut -d "%" -f 1`
  do
  if [ $space -get 80 ] ; then
  echo "Over 80%" | mail -s "report" root@localhost
  else
  echo "Disk space normail" | mail -s "report" root@localhost
  fi
  done

页: [1]
查看完整版本: shell知识