shell习题

目录

一、题目要求

二、编写脚本 

三、设置权限 

四、测试

五、编写脚本

六、设置权限

七、测试

八、编写脚本

九、设置权限

十、测试


一、题目要求

1、判断web服务是否运行(1、查看进程的方式判断该程序是否运行,2、通过查看端口的方式判断该程序是否运行),如果没有运行,则启动该服务并配置防火墙规则。
​2、使用curl命令访问第二题的web服务,看能否正常访问,如果能正常访问,则返回web server is running;如果不能正常访问,返回12状态码。
3、for创建20用户
用户前缀由用户输入
用户初始密码由用户输入
例如:test01,test10

二、编写脚本 

[root@localhost red]# cd /shell
[root@localhost shell]# mkdir chap02
[root@localhost chap02]# vim dem01.sh
[root@localhost chap02]# cat dem01.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 dem01.sh

四、测试

[root@localhost chap02]# ./dem01.sh
httpd is running
[root@localhost chap02]# systemctl stop httpd
[root@localhost chap02]# ./dem01.sh
httpd is start

五、编写脚本

curl -s 192.168.40.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 dem02.sh

七、测试

[root@localhost chap02]# systemctl stop httpd
[root@localhost chap02]# ./dem02.sh
web server is stop
[root@localhost chap02]# echo $?
12
[root@localhost chap02]# systemctl restart httpd
[root@localhost chap02]# ./dem02.sh
web server is running

八、编写脚本

[root@localhost chap02]# vim dem03.sh
[root@localhost chap02]# cat dem03.sh
read -p "please input user prefix:" per
read -p "please input your password:" mima
for number in {01..20}
do
        id $per$number &> /dev/null || useradd $per$number
        echo $mima | password --stdin $mima$number &> /dev/null
done

九、设置权限

[root@localhost chap02]# chmod a+rx dem03.sh

十、测试

[root@localhost chap02]# ./dem03.sh
please input user prefix:tt
please input your password:123
[root@localhost chap02]# id tt01
用户id=1041(tt01) 组id=1041(tt01) 组=1041(tt01)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值