Thanks for taking your time to reply Rich but I have already tried everything in that link. I am not one of these people that log a question in a forum as soon as I hit a glitch, more as a last resort. I feel I learn better that way.
As above, I have tested the execCommand method and it works, returning values as expected in the logs.
The system is running as openhab user
openhab user has a shell set in /etc/passwd
openhab user has permissions to the file etc
I have set a password for openhab user so I can log in as it.
** Logging in as openhab user I can run the script and it works fine
** My script writes to a log file when the script is run and it is running as expected every 10 seconds by openhab, just the response from the command is not being applied to the switch item.
I am aware that SNMP is natively supported, I already use it for other things.
I am specifically not using it here as:
I have 2 access points in my house and I need to enumerate both, this simplifies(?) it
The SNMP query does not directly return all MAC addresses for attached devices from one OID but it has an array of ‘slots’ for each MAC attached, therefore I have to use snmp walk, grepped to strip out just the MAC address I am looking for:
rv1="snmpwalk -Oqv -v 1 -c public 192.168.0.5 220.127.116.11.18.104.22.168.222.214.171.124.8.1.2 | grep -c ‘$macaddr’"
rv2="snmpwalk -Oqv -v 1 -c public 192.168.0.6 126.96.36.199.188.8.131.52.2184.108.40.206.8.1.2 | grep -c ‘$macaddr’"
if [ “$rv1” == 1 ] || [ “$rv2” == 1 ]; then
echo “$macaddr Found” >> /var/log/openhab2/presensedetect
echo “$macaddr not Found” >> /var/log/openhab2/presensedetect
I have also tried ‘exit 0’ and ‘exit 1’ thinking that perhaps it does not accept the console text as the response.
I did have issues at the start which showed up with testing:
- Initially I was trying to log to /var/log/presencedetect - Access denied, changed to /var/log/openhab2/presencedetect
- Openhab adds double quotes to the command passed to the shell script so I had to add code to remove them in the script itself otherwise grep would not find a match.