题目要求 1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。 2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。 3、for创建20用户 用户前缀由用户输入 用户初始密码由用户输入 例如:test01,test10
一,解析过程
[root@localhost chap02]# vim test01.sh
[root@localhost chap02]# cat test01.sh
ps -ef | grep httpd > /dev/null && ss -lntup | grep 80 > /dev/null
if [[ $? = 0 ]];then
echo "httpd is running"
exit;
else
systemctl start httpd
systemctl stop firewalld
echo "httpd is start"
fi
三、设置权限
[root@localhost chap02]# chmod a+rx test01.sh
四、测试
[root@localhost chap02]# ./test01.sh
httpd is running
[root@localhost chap02]# systemctl stop httpd
[root@localhost chap02]# ./test01.sh
httpd is start
五、编写脚本
curl -s 192.168.30.135 &> /dev/null
if [[ $? = 0 ]];then
echo "web server is running"
else
echo "web server is stop"
exit 12
fi
六、设置权限
[root@localhost chap02]# chmod a+rx test02.sh
七、测试
[root@localhost chap02]# systemctl stop httpd
[root@localhost chap02]# ./test02.sh
web server is stop
[root@localhost chap02]# echo $?
12
[root@localhost chap02]# systemctl restart httpd
[root@localhost chap02]# ./test02.sh
web server is running
八、编写脚本
[root@localhost chap02]# vim text03.sh
[root@localhost chap02]# cat text03.sh
read -p "please input user prefix:" a
read -p "please input your password:" mima
for number in {01..20}
do
a$number &> /dev/null || useraa$number
echo $mima | password --stdin $a$number &> /dev/null
done
九、设置权限
[root@localhost chap02]# chmod a+rxtest03.sh
十、测试
[root@localhost chap02]# ./test03.sh
please input user prefix:yyt
please input your password:123456
[root@localhost chap02]# id yyt01
用户id=1041(yyt01) 组id=1041(yyt01) 组=1041(yyt01)