Page 1 of 1

filter executing an external python script

Posted: Wed Oct 20, 2021 2:42 pm
by tchi59
Hi,

I am trying each time an alarm is trigger to execute a python script

When i execute my script from cli it is working
when it is execute from Zone Minder i catch this error

ERR Command '/home/pi/python/ZoneMinderFilter.py /ramdisk/4/397' exited with status: 120

do you know why ?
thx

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 3:39 pm
by kitkat
Have you tried running the script as the apache or www-data user? (Or whatever your distro provides.)

Code: Select all

su -s /bin/bash --command="/home/pi/python/ZoneMinderFilter.py /ramdisk/4/397" apache
If that works, can you capture any runtime output or errors when ZM runs the script, perhaps by writing it to a file with something like this as the command in ZM:

Code: Select all

/home/pi/python/ZoneMinderFilter.py >logfile 2>&1
I'm not sure if that will work though as Zm may well place other parameters at the end of the line which might mess things up.

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 3:47 pm
by tchi59
hi
i did what you advise
but the main problem is that zoneminder add /ramdisk/4/401 at all commands
Command 'su -s /bin/bash --command="/home/pi/python/ZoneMinderFilter.py" apache /ramdisk/4/401' exited with status: 1
do you know why?
Regards

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 3:49 pm
by tchi59
by hand

root@raspberrypi:/home/pi# /home/pi/python/ZoneMinderFilter.py /ramdisk/4/398/ 1>logfile2>&1

root@raspberrypi:/home/pi# cat logfile2
/ramdisk/4/398/
4
398
rclone copy /ramdisk/4/398//398-video.mp4 googledrive:398-video.mp4
/usr/bin/rclone link googledrive:398-video.mp4
b'https://drive.google.com/open?id=1RBVoi ... 8ntl4oHo\n'
echo "b'https://drive.google.com/open?id=1RBVoi ... 8ntl4oHo\n'" | /home/pi/python/SendMail.py LINK3

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 4:01 pm
by tchi59
you are right my ZM seems to run under www-data user

root@raspberrypi:/home/pi# ps -ef |grep zm
www-data 773 1 0 15:09 ? 00:00:01 /usr/bin/perl -wT /usr/bin/zmdc.pl startup
www-data 819 773 48 15:09 ? 01:24:06 /usr/bin/zmc -m 4
www-data 824 773 0 15:09 ? 00:00:01 /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=1 --daemon
www-data 832 773 0 15:09 ? 00:00:01 /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=2 --daemon
www-data 853 773 0 15:09 ? 00:00:04 /usr/bin/perl -wT /usr/bin/zmaudit.pl -c
www-data 859 773 0 15:09 ? 00:00:01 /usr/bin/perl -wT /usr/bin/zmwatch.pl
www-data 873 773 0 15:09 ? 00:00:00 /usr/bin/perl -wT /usr/bin/zmtelemetry.pl
www-data 879 773 0 15:09 ? 00:00:00 /usr/bin/perl -wT /usr/bin/zmstats.pl
www-data 19955 773 0 17:44 ? 00:00:02 /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=3 --daemon
root 20617 20240 0 18:01 pts/1 00:00:00 grep zm

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 4:05 pm
by kitkat
I suspect that the script may not be executable by, or that some file is inaccessible to, the www-data user.

Try this at the command line:

Code: Select all

su -s /bin/bash --command="/home/pi/python/ZoneMinderFilter.py /ramdisk/4/397" www-data

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 4:11 pm
by tchi59
from root this command works !

root@raspberrypi:/home/pi/python# su -s /bin/bash --command="/home/pi/python/ZoneMinderFilter.py /ramdisk/4/397" www-data
/ramdisk/4/397
4
397
rclone copy /ramdisk/4/397/397-video.mp4 googledrive:397-video.mp4
/usr/bin/rclone link googledrive:397-video.mp4
b'https://drive.google.com/open?id=1JpyVR ... xUF0BW6x\n'
echo "b'https://drive.google.com/open?id=1JpyVR ... xUF0BW6x\n'" | /home/pi/python/SendMail.py LINK3

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 4:23 pm
by tchi59
thanks to you i find the trick !!!

well, i allow www-data to do su (adding in /etc/passwd on the www-data line => /bin/bash)
i configured www-data user to be able to copy on googledrive with rclone

now it is working with that command in filter ==> /home/pi/python/ZoneMinderFilter.py


THANKS YOU !

Re: filter executing an external python script

Posted: Wed Oct 20, 2021 8:38 pm
by kitkat
Good to hear it's fixed - It sounds like the www-data user didn't have a shell configured :)

The "proper"/"safe" way to add or change a user's shell or other data is with usermod though, which'll update /etc/passwd and any other relevant files...

Code: Select all

usermod -s /bin/bash www-data