运维开发网

从0开始学习shell ---简单shell小程序练手

运维开发网 https://www.qedev.com 2021-04-25 12:37 出处:51CTO 作者:进击的闪电
shell;if

判断进程是否正常存在

[root@localhost shell]# cat http.sh

#!/bin/env

pgrep httpd &> /dev/null

if [ $? -ne 0 ];then

echo "no httpd"

else

echo "httpd"

fi

[root@localhost shell]# cat http1.sh

#!/bin/env

pgrep httpd &> /dev/null

test $? -eq 0 && echo "httpd" || echo "no httpd"

[root@localhost shell]#

判断网站服务是否正常

Wget curl elinks --dump

[root@localhost shell]# cat service.sh

#!/bin/env bash

web_server=www.itcast.cn

wget -P /root/shell $web_server &> /dev/null

[ $? -eq 0 ] && echo "service is ok" && rm -f /root/shell/index.* || echo "service is not ok"

[root@localhost shell]#

打印1,3,5,7,9

1-10 步长是2 (也就是间隔2)

[root@localhost shell]# seq 1 2 10

1

3

5

7

9

0

精彩评论

暂无评论...
验证码 换一张
取 消