I have a python script that reads last line of a text file (present in location /home/anas/projects) and prints it. Text file contains a single float value on each line. When i run this python script from terminal, it works fine. The problem i am having is that i want to use this script with snmp. So i have used snmp extend and added
extend snmp-datarate /usr/bin/python2.7 /usr/local/bin/snmp-feedback.py
in /etc/snmp/snmpd.conf file. and when i run this command
snmpwalk -v2c -c public 127.0.0.1 NET-SNMP-EXTEND-MIB::nsExtendObjects
it gives me following error,
NET-SNMP-EXTEND-MIB::nsExtendOutLine."snmp-datarate".4 = STRING: OSError: [Errno 13] Permission denied: '/home/anas/projects'
Now i thought that it could eb due to use of python so i also tried shell script, named it snmp-agra-datarate.sh, which only have two lines of code
#!/bin/bash
echo $( tail -n 1 /home/anas/projects/6780-log.txt )
Running this script from terminal produces the expected output. I then extended snmp with
extend datarate /usr/local/bin/snmp-agra-datarate.sh
then when i try to run snmp walk again. i get similar error
NET-SNMP-EXTEND-MIB::nsExtendOutLine."datarate".2 = STRING: tail: cannot open '/home/anas/projects/6780-log.txt' for reading: Permission denied
Is there something i am missing in order to read external text file with python or shell for extended snmp agent?
-i am using ubuntu 16.04 LTS and net-snmp v5.8
-Both python and shell scripts have execute permissions. (i did chmod 755)
-text file also have all permissions
The error message
Permission denied: '/home/anas/projects'
is pointing to the permissions of that directory. If too restrictive, then the snmpd cannot go in there.
To solve the problem, do a
ls -ld /home/anas/projects
and that will give you a clue.