以 nrpe 用户身份运行 bash 脚本失败

以 nrpe 用户身份运行 bash 脚本失败

我创建了一个 bash 脚本,用于在多台服务器上的所有日志文件夹中进行搜索,并压缩基于 rpm 的机器(RHEL 和 Centos 6 & 7 服务器)上的所有日志文件。该脚本用于创建一个锁定文件以防止多个实例运行,并且整个脚本(大量使用 find 和 tar 以及 rm 命令)用于在触发 Nagios 事件处理程序时由具有 sudo 权限的 nrpe 用户运行。

我已授予 nrpe sudo 权限以运行此命令,但我注意到当我尝试运行脚本时出现权限被拒绝的情况:

sudo -u nrpe /share/username/run/fixstorage.sh
touch: cannot touch `/var/run/fixstorage.lockfile': Permission denied
find: `/var/log/sssd': Permission denied
find: `/var/log/salt': Permission denied
find: `/var/log/httpd': Permission denied
find: `/var/log/audit': Permission denied

但随后脚本似乎继续运行,但没有任何输出。并且存储不固定。我怎样才能让 nrpe 正确运行整个脚本?脚本上的权限是:

-rwxrwxr-x. 1 username username 5516 Jan  3 23:36 /share/username/run/fixstorage.sh

它位于 NFS 安装的用户主文件夹中。

相关内容