shell编程实战9
其他
2019-09-06 00:44:34
阅读次数: 0
1. 根据网卡名输出IP
#!/bin/bash
ip addr|grep ^[0-9]|awk -F '[: ]+' '{print $2}'>/tmp/eth.list ##利用死循环来提示用户输入正确的网卡名,输入正确的网卡名后跳出死循环 while : do echo "The network card is `cat /tmp/eth.list|xargs`" #多行合并为一行 read -p "请输入网卡名:" x if [ -z "$x" ] then echo "请输入一个网卡名" continue fi if ! grep -qw "$x" /tmp/eth.list then echo "输入的网卡名不存在,请输入正确的网卡名" continue else break fi done ## 一个网卡一个IP的情况,ip写入变量中 #ip=`ip addr show dev eth0|grep -w "inet"|awk '{print $2}'|awk -F / '{print $1}'` #echo "The $x ip is $ip" ## 一个网卡多个IP的情况,IP写入文件中 net_ip() { ip addr show dev eth0|grep -w "inet"|awk '{print $2}'|awk -F / '{print $1}' >/tmp/$1.txt n=`wc -l /tmp/$1.txt|awk '{print $1}'` if [ $n -eq 0 ] then echo "the $1 没有IP" else echo "the $1 ip is:" cat /tmp/$1.txt fi } net_ip $x |
2. 列出目录内容
3. 下载文件
#!/bin/bash if [ $# -ne 2 ] then echo "必须输入2个参数,第一个参数为网站,第二参数为目录" exit 1 fi
扫描二维码关注公众号,回复:
7186780 查看本文章
if [ ! -d $2 ] then while : do echo "$2目录不存在,是否创建该目录?(y|n)" read c case $c in y|Y) mkdir -p $2 break ;; n|N) exit 51 ;; *) echo "请输入y或者n" continue ;; esac done else cd $2 wget $1 if [ $? -eq 0 ] then exit 0 else echo "下载失败" exit 52 fi fi |
4. 猜数字
5.
转载自www.cnblogs.com/tanzhirong/p/11470592.html