第二周作业
#!/bin/bash
echo -e "\e[1;32m"
cat <<EOF
1)显示IP地址
2)判断IP地址
(含3打印系统时间;不含3则创建用户且属于magedu组)
3)打印用户
4)安装nginx服务
EOF
echo -e "\e[0m"
read -p "请输入序号(1-4):" NUMER
if [ $NUMER -eq 1 ]; then
echo "`ifconfig ens160|sed -rn "s/.*inet ([0-9.]+) +netmask.*$/\1/p"`"
elif [ $NUMER -eq 2 ]; then
IP=`ifconfig ens160|sed -rn "s/.*inet ([0-9.]+) +netmask.*$/\1/p"`
[[ "$IP" =~ ^(.*[3].*+)\.|([3]+)\.|([3]+)\.|(.*[3].*+)$ ]] && { date;exit; } || groupadd magedu
for i in {1..100}; do
useradd magedu_0$i
usermod -G magedu magedu_0$i
done
elif [ $NUMER -eq 3 ]; then
grep -v nologin /etc/passwd
elif [ $NUMER -eq 4 ]; then
yum -y install nginx
else exit
fi

浙公网安备 33010602011771号