I just installed nagios and nrpe-version nrpe-4.1.0 on Ubuntu 22.04. Its a host machine which connects to nagios server. When I'm passing a check to run a script /usr/local/nagios/libexec/check_sync.sh
. This runs fine under user 'ubuntu' but if I check it via
sudo su nagios -c "/usr/local/nagios/libexec/check_sync.sh"
Getting error as
cat: /home/ubuntu/health.txt: Permission denied
bash: [: =: unary operator expected
Same error to what I get on when nagios server tries to check it. Basically don't think under user 'nagios' its able to read that file. I tried changing the permission on that file, but that doesn't work. This is first time I'm running nrpe on Ubuntu 22.04, not sure if thats linked in anyway. Its the same error when I perform:
sudo su - nagios -c "cat /home/ubuntu/health.txt"
The file is definitely there and permissioned to read by all. The script starts with:
#!/bin/bash -i
Any ideas what can be done about it?
#Updated#
Running on ubuntu LTS 22.04: Cronjob runs a command which places a health.txt file to
/home/ubuntu/health.txt
Below script is under:
/usr/local/nagios/libexec/check_sync.sh
the script runs to see a string value is false or true
#!/bin/bash -i
catchup=$(cat /home/ubuntu/health.txt | awk -F"," '{print $20}' | awk -F"}" '{print $1}'| awk -F":" '{print $2}')
if [ $catchup = "false" ]; then
echo "Node is synced"
exit 0
else
echo "Not Synced"
exit 2
fi
If I run just the script it works fine and gives the value.
But if I run: sudo su nagios -c "/usr/local/nagios/libexec/check_sync.sh" I get:
bash: cannot set terminal process group (110223): Inappropriate ioctl for device
bash: no job control in this shell
cat: /home/ubuntu/health.txt: Permission denied
bash: [: =: unary operator expected
Not Synced
I tried to change the directory for health.txt from /home/ubutu/ to /tmp/health.txt so that user nagios can read it, so now when I run:
sudo su nagios -c "/usr/local/nagios/libexec/check_sync.sh"
bash: cannot set terminal process group (170765): Inappropriate ioctl for device
bash: no job control in this shell
Node is synced
But, still running on nagastamon is showing as "Not synced" which means its still either not reading the file correctly.
namei -l /home/ubuntu/health.txt
f: /home/ubuntu/health.txt
drwxr-xr-x root root /
drwxr-xr-x root root home
drwxr-x--- ubuntu ubuntu ubuntu
-rw-rw-r-- ubuntu ubuntu health.txt