#!/bin/bash
#***********************************
#* time 2022-08-05
#* scriptname: N68Week2Homework.sh
#* email: 316774217@qq.com
#***********************************
IPAdd=$(ifconfig ens33| sed -nr '2s/^.*inet//;s/netmask.*//p')
echo "本地ip地址是:" $IPAdd
echo "正在检查地址是否包含数字3"
Have3=$(echo $IPAdd | grep [3]|echo $?)
echo $Have3
case $Have3 in
"0")
echo "检查到3的存在开始打印时间"
date=$(date)
echo "当前时间为:$date"
;;
*)
echo "未检测到3,开始建立用户"
groupadd "magedu"
for i in {1..100};do
useradd "magedu$i" -g magedu
done
;;
esac
echo "当前计算机可登陆用户为"
cat /etc/passwd | grep -v "nologin"|cut -d: -f1|tr -s '\n' "|"
echo -e
#. 与bash不一样,不开启子进程下执行脚本
. /etc/os-release
#执行os-relase文件,获得$ID变量
if [ $ID == "rocky" -o $ID == "centos" ];then
echo OS version is rocky or centos
yum -y install ngnix
elif [ $ID == "ubuntu"];then
echo OS version is ubuntu
apt -y install ngnix
else
echo system do no support
fi
网友评论