add pgrep

This commit is contained in:
nick 2019-01-30 21:22:48 +08:00
parent 9fb17700b4
commit cb88913ac5
2 changed files with 27 additions and 0 deletions

19
demo.md
View File

@ -14,6 +14,25 @@ if [ "$port" == "" ]; then
fi fi
``` ```
#### 检测指定服务是否正常运行
新建文件写入以下内容
```
#!/usr/bin/env bash
read name
pgrep $name > /dev/null
if [ $? -gt 0 ];then
echo "`date` $name is stop" >> ~/mysql_listen.log
systemctl $name mysql
else
echo "`date` $name running" >> ~/mysql_listen.log
fi
```
给脚本添加执行权限后运行,输入服务名称即可
设置定时任务 设置定时任务
``` ```

View File

@ -321,3 +321,11 @@ bg 1 #将任务编号为 1 调到后台运行
fg 1 #将任务编号为 1 调到前台运行 fg 1 #将任务编号为 1 调到前台运行
``` ```
#### pgrep 命令
```
pgrep nginx # 查看 nginx 进程
pgrep -l nginx #查看 nginx 进程名称
```