1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
[root@localhost chap02]# vim test2.sh #脚本文件test2.sh内容: read -p "请输入您想查询的进程:" process ss -lntup | grep $process &> /dev/null if [ "$?" -eq 0 ];then echo "$process is running!" else echo "$process is not runnig!" systemctl start $process fi [root@192 chap02]# bash test2.sh #执行脚本文件test2.sh [root@localhost chap02]# vim test2.sh #编辑脚本文件内容: #!/bin/bash if [ "`ps -ef | grep httpd | wc -l`" -gt 1 ]; then echo "httpd is running !" else echo "httpd is not running!" systemctl start httpd &> /dev/null fi
2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
[root@localhost day]# vim test3.sh #编写脚本文件内容: #!/bin/bash systemctl restart httpd systemctl stop firewalld setenforce 0 curl https://192.168.122.1 -k &> /dev/null if [ "$?" -eq 0 ];then echo "webserver is running!" cat /www/https/index1.html else echo "12" fi
3、for创建20用户 用户前缀由用户输入 用户初始密码由用户输入 例如:test01,test10
read -p "请输入用户名前缀:" name read -p "请输入用户数量:" number read -p "请输入密码:" passwd if [ ! -z "$name" -a ! -z "$number" -a ! -z "$passwd" ] then y=$(echo $number | sed 's/[0-9]//g') if [ -z "$y" ] then for ((i=1;i<=$number;i+=1)) do useradd $name$i &> /dev/null echo $passwd | /usr/bin/passwd --stdin $name$i &> /dev/null done fi fi