首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Monit:如何检查由特定用户执行的程序?

Monit:如何检查由特定用户执行的程序?
EN

Server Fault用户
提问于 2014-09-22 05:30:25
回答 1查看 811关注 0票数 0

我一直在使用monit/mmonit来监视我的系统。如果它的一个特性是check program语法,它运行一个程序并验证它的返回值:

代码语言:javascript
复制
# Asserts that there are more than 40 users in the DEV DB.

check program more_than_40_users_in_dev_db 
    with path /home/ubuntu/servers-scripts/monitoring/more_than_40_users_in_dev_db.py
    with timeout 5 seconds
    every 2 cycles
    if status != 0 then alert

问题是脚本应该以用户ubuntu的身份运行,但是monit以root的形式运行。我尝试过as uid ubuntu and gid ubuntu语法,但它似乎不适用于check program指令。

是否有办法以特定用户的身份运行此脚本?

EN

回答 1

Server Fault用户

发布于 2020-09-04 22:08:17

在这几年中,这种情况可能发生了变化,但只要monit作为root运行(例如,systemd服务),就可以用as uid abc and as gid abc语法来实现这一点:

代码语言:javascript
复制
# You can also shorten to 'as gid user and uid user'; both formats work for me with v5.26.0
check program somescript with path /home/user/somescript.sh as gid user and as uid user
    if status != 0 then alert

somescript.sh在哪里

代码语言:javascript
复制
#!/bin/bash

whoami > /home/user/whoami.out

当然,您也可以使用用户所属的另一个gid (例如sharing),生成的文件将使用所有权user:sharing创建,并包含“user”。

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/630224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档