#网卡和IP #!/bin/bash ip add |awk -F ": " ‘ ~ "^[0-9]" {print }‘ > /tmp/ifs.txt get_ip() { ip add show dev |grep inet |awk ‘{print }‘ | awk -F ‘/‘ ‘{print }‘ } for eth in `cat /tmp/ifs.txt` do myip=`get_ip $eth` if [ -z "$myip" ] then etho $eth else echo $eth $myip fi done > /tmp/if_ip.txt if [ $# -ne 2 ] then echo "请输入正确格式: bash -i 网卡 或 bash -I IP" fi if [ == "-i" ] then if awk ‘{print }‘ /tmp/if_ip.txt|grep -qw then ip1=`awk -v aeth= ‘==aeth ‘ /tmp/if_ip.txt|sed "s/$eth //"` echo "网卡的IP是 $ip1" else echo "你指定的网卡不对,系统中的网卡前:`cat /tmp/ifs.txt|xargs`" fi elif [ == "-I" ] then if grep -qw "" /tmp/if_ip.txt then eth=`grep -w " " /tmp/if_ip.txt|awk ‘{print }‘` echo "IP 对应的网卡是 $eth" else echo "你指定的IP不对,系统中的IP有:`ip add |grep inet |awk ‘{print }‘|awk -F ‘/‘ ‘{print }‘`| xargs" fi else echo "清输入正确的格式:bash -i 网卡 或 bash -I IP" fi #随机三位数 #!/bin/bash get_number() { for i in `seq 0 2` do a[$i]=$[$RANDOM%10] done echo ${a[@]}|sed s‘/ //g‘ } if [ $# -eq 0 ] then get_number elif [ $# -eq 1 ] then n=`echo |sed ‘s/[0-9]//g‘` if [ -n "$n" ] then echo "给定的参数必须是一个数字" exit fi for i in `seq 1 ` do get_number done |xargs else echo "格式不对, 正确格式是 sh [n]" fi #是否是安装包 #!/bin/bash if_install() { rpm -q >/dev/null 2>/dev/null if [ $? -eq 0 ] then echo "已经安装" return 0 else echo "没有安装" return 1 fi } if_install httpd if [ $? -eq 0 ] then if ! pgrep httpd >/dev/null then service httpd start fi else yum install -y httpd fi if_install MysqL-server if [ $? -eq 0 ] then if ! pgrep MysqLd >/dev/null then service MysqLd start fi else yum install -y MysqL-server fi #判断日期是否合法 #!/bin/bash if [ $# -ne 1 ] || [ ${#1} -ne 8 ] then echo "请输入正确格式:sh yyyymmdd" exit 1 fi y=`echo ${1:0:4}` m=`echo ${1:4:2}` d=`echo ${1:6:2}` if echo $d|grep -q "^0" then d=`echo ${1:6:2}|sed ‘s/^0//‘` fi if cal $m $y >/dev/null 2>/dev/null then if ! cal $m $y |grep -qw "$d" then echo "你给的日期不是合法的" else echo "日期合法" fi else echo "你给的日期不合法" fi #监控网卡 #!/bin/bash LANG=en sar -n DEV 1 10 |grep -w "" > /tmp/sar.tmp in=`grep "Average:" /tmp/sar.tmp|awk ‘{print }‘|sed ‘s/\.//‘` out=`grep "Average:" /tmp/sar.tmp|awk ‘{print }‘|sed ‘s/\.//‘` if [ $in == "00" ] && [ $out == "00" ] then ifdown ifup fi
总结 以上是内存溢出为你收集整理的SHELL训练营--day21_shell练习46-50全部内容,希望文章能够帮你解决SHELL训练营--day21_shell练习46-50所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)