1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
3、for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10
1.1
[root@client_2 homework3]# vim text1.1.sh
#!/bin/bash
ps_httpd=`ps -ef | grep httpd | grep -v grep | wc -l`
if [[ $ps_httpd > 0 ]];then
echo "httpd.service is running."
else
systemctl start httpd
systemctl stop firewalld
fi
加权限
[root@client_2 homework3]# chmod a+rx text1.1.sh
1.2
[root@client_2 homework3]# vim text1.2.sh
#!/bin/bash
port80=`ss -lntup | grep -w 80 | wc -l`
if [[ $port80 > 0 ]];then
echo "httpd.service is running."
else
systemctl start httpd
systemctl stop firewalld
fi
加权限
[root@client_2 homework3]# chmod a+rx text1.2.sh
2.
[root@client_2 homework3]# vim test02.sh
#!/bin/bash
curl -s 192.168.16.128 > /dev/null
if [[ $? = 0 ]];then
echo "web server is running."
else
exit 12
fi
加权限
[root@client_2 homework3]# chmod a+rx test02.sh
3.
#!bin/bash
read -p "请输入用户前缀和密码:" name password
for i in {1..20}
do
useradd $name$i;
echo $password | passwd --stdin $name$i;
done
加权限
[root@client_2 homework3]# chmod a+rx test03.sh