Bash:运行服务(如果尚未运行)(Centos,Apache,Clam)

编程入门 行业动态 更新时间:2024-10-23 07:33:13
本文介绍了Bash:运行服务(如果尚未运行)(Centos,Apache,Clam)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

编写一个将要运行的简单bash脚本,以检查httpd(apache)或clamd(防病毒)是否在我的Centos服务器上运行,如果没有运行,它将重新启动它们.

Wrote a simple bash script which is to be run in order to check if httpd (apache) or clamd (antivirus) is running on my Centos server, and if not it will restart them.

#!/bin/bash if [[ ! "$(/sbin/service httpd status)" =~ "running" ]] then service httpd start elif [[ ! "$(/sbin/service clamd status)" =~ "running" ]] then service clamd start fi

通过命令行对其进行了测试,因此可以正常工作,但是有没有办法进一步优化呢?

tested it via the command line so it works, but is there any way to optimize this further?

推荐答案

不要关心文本,只需检查返回值即可.

Stop caring about the text and just check the return values.

#!/bin/sh service httpd status &> /dev/null || service httpd start service clamd status &> /dev/null || service clamd start

或者只是不在乎他们已经在运行,让系统来处理它.

Or just don't care that they're already running and let the system handle it.

#!/bin/sh service httpd start service clamd start

更多推荐

Bash:运行服务(如果尚未运行)(Centos,Apache,Clam)

本文发布于:2023-11-23 19:46:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622664.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Centos   Bash   Clam   Apache

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!