第二周作业
#!/bin/bash #1.显示本机的ip地址 Ipaddr=`ifconfig ens160 | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -n1` echo $Ipaddr #2.如果ip地址有3这个数字就打印当前系统时间 #3.如果IP地址不含3这个数字,就批量建立用户magedu_00,magedu_01,magedu_100,并且所有用户属于magedu组 if echo $Ipaddr |grep '3'; then echo $(date +"%Y-%m-%d %H:%M:%S") else for num in {00..100};do groupadd magedu &> /dev/null && useradd magedu_$num -g magedu &> /dev/null || useradd magedu_$num -g magedu &> /dev/null #userdel -rf magedu_$num &> /dev/null;groupdel magedu &> /dev/null done fi #4.打印出/etc/passwd文件中可以登陆的用户(非/usr/sbin/nologin) cat /etc/passwd | grep -v "/sbin/nologin" #5.yum安装nginx服务,并且启动该该服务 . /etc/os-release if [ $ID = "rocky" -o $ID = "centos" ];then echo OS version is rocky or centos yum -y install nginx && systemctl start nginx systemctl status nginx elif [ $ID = "ubuntu" ];then echo OS version is Ubuntu apt update apt -y install nginx && systemctl start nginx systemctl status nginx else echo "不支持OS" exit fi #6.完成脚本