1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
#1. 基于服务状态配置
#!/bin/bash
#########################
#File name:1.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 19:53:53
#Description:
#########################
systemctl status httpd &> /dev/null
if [ "$?" -ne 0 ];then
systemctl start httpd
firewall-cmd --permanent --add--service="http"
echo "httpd start runing"
else
echo "httpd is runing"
fi
#2. 基于服务进程配置
#!/bin/bash
2 #########################
3 #File name:1.sh
4 #Version:v1.0
5 #Email:admin@test.com
6 #Created time:2023-04-06 19:53:53
7 #Description:
8 #########################
9 num=`ps -ef | grep httpd | wc -l`
10 if [ "$num" -le 1 ];then
11 systemctl start httpd
12 firewall-cmd --permanent --add--service="http"
13 echo "httpd start runing"
14 else
15 echo "httpd is runing"
16 fi
#3. 基于端口配置
#!/bin/bash
2 #########################
3 #File name:1.sh
4 #Version:v1.0
5 #Email:admin@test.com
6 #Created time:2023-04-06 19:53:53
7 #Description:
8 #########################
9 num=`ss -lntup | grep 80 | wc -l`
10 if [ "$num" -eq 0 ];then
11 systemctl start httpd
12 firewall-cmd --permanent --add--service="http"
13 echo "httpd start runing"
14 else
15 echo "httpd is runing"
16 fi
#三种配置测试一致
[root@localhost shell]# curl www.openlab.com 192.168.181.100
curl: (6) Could not resolve host: www.openlab.com
wellcom openlab
2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is
running;如果不能正常访问,返回12状态码。
#配置如下
[root@localhost shell]# cat 2.sh
#!/bin/bash
#########################
#File name:2.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 21:31:18
#Description:
#########################
curl www.openlab.com 192.168.181.100 &> /dev/null
if [ "$?" -ne 0 ];then
exit 12
else
echo "web server is running"
fi
#测试如下
[root@localhost shell]# ./2.sh
web server is running
3、for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10
#配置如下
[root@localhost shell]# cat 3.sh
#!/bin/bash
#########################
#File name:3.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-04-06 21:36:54
#Description:
#########################
for name in `seq -f %01g 20`
do
read -p "enter one user name:" username
user_name=$username$name
useradd $user_name
passwd $user_name
done
#测试如下
[root@localhost shell]# ./3.sh
enter one user name:chenbo
更改用户 chenbo1 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
enter one user name:^C
[root@localhost shell]# ls /home
chenbo chenbo1