简单脚本应用
通过ifconfig命令结果找到ip地址
#下载依赖包
yum -y install net-tools-2.0-0.52.20160912git.el8.x86_64
[ root@centos8\ [ ~]#
1、ifconfig |grep -i mask|grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' |head -1
2、ifconfig |head -n2 |tail -n1| tr -s ' ' |cut -d ' ' -f3
3、ifconfig |sed -rn '2s/.*inet ([0-9.]+) .*/\1/p'
显示ifconfig命 令结果中所有IPv4地址 :
1、ifconfig |sed -rn 's/.*inet ([0-9.]+) .*/\1/p'
2、ifconfig |egrep "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"|tr -s ' '|cut -d ' ' -f3
使用脚本判断 你主机所在网络内在线的主机IP有哪些? ping通则在线
普通版
NET=10.0.0
cat /dev/null > hosts.txt
for i in {1..254};do
if ping -c1 -w1 $NET.$i &> /dev/null ;then
echo $NET.$i is up | tee -a hosts.txt
fi
done
#或者
NET=10.0.0
cat /dev/null > hosts2.txt
for ((i=1;i<=254;i++));do
if ping -c1 -w1 $NET.$i &> /dev/null ;then
echo $NET.$i is up | tee -a hosts2.txt
fi
done
后台执行版
#!/bin/bash
NET=10.0.0
cat /dev/null > hosts2.txt
for i in {1..254};do
{
if ping -c1 -w1 $NET.$i &> /dev/null ;then
echo $NET.$i is up | tee -a hosts2.txt
fi
}& 后台并行执行,节省时间
done
wait 程序退出可直接退出,不用按回车
使用while read line和/etc/passwd,计算用户id总和
while read line; do echo $line; done < /etc/passwd |cut -d: -f3|paste -d"+" -s|bc
第三周作业
tcp/ip
一键编译安装httpd
更改网络配置
软件包管理及初始化设置