1.判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
a=`ps -ef | grep httpd | grep -v grep | wc -l`
b=`ss -lntup | grep httpd | wc -l`
if [ $a -gt 0 ] && [ $b -gt 0 ]
then
echo "web is running"
else
systemctl restart httpd;
if [ $? -eq 0 ]
then
echo "启动成功"
else
echo "启动失败"
fi
systemctl disable firewalld
fi
2.使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
curl 192.168.177.129 > /dev/null
if [ $? -eq 0 ]
then
echo "web server is running"
else
echo "web server is not running";
exit 12
fi
3.for创建20用户 用户前缀由用户输入 用户初始密码由用户输入 例如:test01,test10
read -p "请输入用户名称:" name
read -p "请输入密码:" passwd
for username in ${name}{01..20}
do
useradd $username
echo $passwd | passwd --stdin $username > /dev/null
echo "$username 成功加入"
done