rhce第五次作业

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

查看进程

[root@localhost textshall]# vim zhuoye1.sh
num=`ps -ef | grep httpd | wc -l`
if [ $num -gt 1 ];then
        echo httpd is running
else
        systemctl restart httpd > /dev/null
        echo httpd is running for you
fi
[root@localhost textshall]# bash zhuoye1.sh 
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ****                    
httpd is running for you
[root@localhost textshall]# 
[root@localhost textshall]# bash zhuoye1.sh 
httpd is running

​查看端口

[root@localhost textshall]# vim zhuoye1.sh
num=`ss -lntup | grep -w 443 | wc -l`
if [ $num -gt 0 ];then
        echo httpd is running
else
        systemctl restart httpd > /dev/null
        echo httpd is running for you
fi
[root@localhost textshall]# bash zhuoye1.sh 
🔐 Enter TLS private key passphrase for www.openlab.com:443 (RSA) : ****                    
httpd is running for you
[root@localhost textshall]# 
[root@localhost textshall]# bash zhuoye1.sh 
httpd is running

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

[root@localhost ~]# vim curl.sh
curl www.openlab.com &> /dev/null
if [ $? -eq 0 ];then
        echo web is running
else
        exit 12
fi
[root@localhost ~]# bash curl.sh 
web is running
[root@localhost ~]# 

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

[root@localhost ~]# vim useradd.sh
read -p "enter username:" name
read -p "enter passwd:" passwd
for i in {1..10}
do
        namer=${name}${i}
        useradd $namer -p $passwd
done
[root@localhost ~]# bash useradd.sh 
enter username:text
enter passwd:123
[root@localhost ~]# 
[root@localhost ~]# cat /etc/passwd
text1:x:1012:1012::/home/text1:/bin/bash
text2:x:1013:1013::/home/text2:/bin/bash
text3:x:1014:1014::/home/text3:/bin/bash
text4:x:1015:1015::/home/text4:/bin/bash
text5:x:1016:1016::/home/text5:/bin/bash
text6:x:1017:1017::/home/text6:/bin/bash
text7:x:1018:1018::/home/text7:/bin/bash
text8:x:1019:1019::/home/text8:/bin/bash
text9:x:1020:1020::/home/text9:/bin/bash
text10:x:1021:1021::/home/text10:/bin/bash

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值