上海isp 发表于 2018-8-24 07:24:03

shell之常用脚本

  1 批量创建用户:
  #!/bin/bash
  i=30

  groupadd>  while [ $i -le 50 ]
  do

  if>  then
  echo "This user$i is exist"
  else

  useradd -g>  fi
  ((i++))
  done
  2 检测主机是否存活:
  #!/bin/bash
  host=192.168.154.
  i=120
  while [ $i -le 130 ]
  do
  ping -c 3 $host$i &> /dev/null
  if [ $? -eq 0 ]
  then
  echo "This host $host$i is up"
  else
  echo "This host $host$i is down"
  fi
  ((i++))
  done
  3 获取局域网IP——MAC地址列表:
  #!/bin/bash
  host=192.168.154.
  i=1
  while [ $i -le 10 ]
  do
  arping -c 2 $host$i | egrep 'reply' | awk -F ' ' '{print $4 $5}' >> /root/c.txt
  ((i++))
  done

页: [1]
查看完整版本: shell之常用脚本