【第五次作业】

1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则

 <1>用查看进程

vim test1.sh
#!/bin/bash
num=`ps -ef | grep -c httpd`
if [ $num -ge 1 ];then
        echo "httpd is running"
else
        echo "httpd not running"
        systemctl start httpd &> /dev/null
fi

chmod +x test1.sh
[root@localhost shtest]# ./test1.sh 
httpd is running

[root@localhost shtest]# ./test1.sh 
httpd not running

 <2>用查看端口

vim test2.sh
#!/bin/bash
num=`ss -lntup | grep -cw 80`
if [ $num -ge 1 ];then
        echo "httpd is running"
else
        echo "httpd not running"
        systemctl start httpd &> /dev/null
fi

chmod +x test2.sh
[root@localhost shtest]# ./test2.sh 
httpd is running

[root@localhost shtest]# ./test2.sh 
httpd not running

 ​2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码

vim test3.sh
curl http://192.168.17.128 &> /dev/null
num=`echo $?`
if [ $num -eq 0 ];then
        echo "web server is running"
else
        echo "web server not running"
        exit 12
fi


chmod +x test2.sh
./test3.sh
[root@localhost shtest]# ./test3.sh 
web server not running
[root@localhost shtest]# echo $?
12
[root@localhost shtest]# ./test3.sh 
web server is running

 3、for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10

[root@localhost shtest]# vim test4.sh
#!/bin/bash
read -p "please input name:" a
read -p "please input sercert:" b
for i in {01..20}
do
        if [ $i -lt 10 ]
        then
                user="$a""$i"
        else
                user="$a""$i"
        fi

        if ! id -u $user &> /dev/null
        then
                useradd $user
        echo "$b" | passwd --stdin $user &> /dev/null
        else
        echo "$user is exists..."
        fi
done


[root@localhost shtest]# ./test4.sh 
please input name:ll
please input sercert:123

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值