LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   motion daemon not able to send email (debian) (https://www.linuxquestions.org/questions/linux-software-2/motion-daemon-not-able-to-send-email-debian-4175457717/)

NozeDive 04-10-2013 03:34 PM

motion daemon not able to send email (debian)
 
I've installed and configured motion to run as a daemon. Right now, all I want it to do is detect motion and then execute a command. At the moment, the program will detect motion, and then log the date and time to a text file located in /etc/motion. That much is working. I've put this line in the config file for that camera:

Code:

on_motion_detected date >> /etc/motion/blarg.txt
So, it detects motion, and then it writes the date and time to that file.

I also have this line in the config file:

Code:

on_motion_detected sh /etc/motion/sendtony.sh
That script sends an email to my cellphone number. I can run it as root or as the normal user tony and it works fine (I type sh sendtony.sh and a few second later, my phone buzzes with the message) however, it does not work when the motion daemon is supposed to be executing the script.

The contents of that script are:

Code:

#!bin/bash
msmtp -t < tonymsg

The contents of tonymsg are:
Code:

To: REDACTED@REDACTED.com
From: REDACTED@REDACTED.com
Subject: Test Message

This is a test message.

REDACTED@REDACTED.com
--Tony's SheevaPlug--

I don't think the contents of the message are really relevant, but I included it anyway just in case.

msmtp uses the universal config file (not the best solution, but for testing, that's how it's set up) msmtprc located at /etc/msmtprc. Its contents follows:

Code:

account default
host mail.REDACTED.com
port 26
from REDACTED@REDACTED.com
tls on
tls_starttls on
tls_certcheck off
auth on
user REDACTED.com
password REDACTED
logfile ~/.msmtp

I don't understand why the motion daemon cannot execute that script. My best guess is that it's a permissions issue, since the script can be executed from the command line as root or as tony (a normal user), but the motion daemon doesn't seem to be able to execute it, although it does execute the command that writes the date and time of motion to a text file.

Since I think it's a permissions issue, I checked the owners, groups, and permissions, and it seems to me that they should all be readable and executable by any user on the system (again, not the best solution, but I'll restrict it once I get this testing finished)

Code:

drwxrwxrwx  2 root  root    4096 Apr 10 16:04 .
drwxr-xr-x 68 root  root    4096 Apr 10 15:21 ..
-rw-r--r--  1 motion motion    29 Apr 10 16:04 blarg.txt
-rw-r-----  1 root  motion 24272 Apr  3 13:35 motion.conf
-rwxr-xr-x  1 tony  tony      70 Apr 10 15:36 sendtony.sh
-rw-r--r--  1 root  root    2385 Apr  3 13:20 thread1.conf
-rw-r--r--  1 root  root    2544 Apr 10 15:48 thread2.conf
-rw-r--r--  1 root  root    2110 Aug 10  2010 thread3.conf
-rw-r--r--  1 root  root    2625 Aug 10  2010 thread4.conf
-rwxr-xr-x  1 tony  tony    152 Apr 10 15:36 tonymsg

I emboldened the pertinent files. It looks like they can be read and executed by everyone (except blarg, which is written by the motion daemon)

And here's the permissions of the config file for msmtp:

Code:

-rw-r--r-- 1 root  root    257 Apr  7 19:40 msmtprc
It looks like everyone can read the file, so msmtp should be able to read it when called from that script I mention further up in this post.

So, why can't the motion daemon run that script?

:-(

P.S.
Debian on a SheevaPLug
uname output:
Code:

Linux debian-tony-server 2.6.32-5-kirkwood #1 Mon Feb 25 13:55:40 UTC 2013 armv5tel GNU/Linux

pan64 04-11-2013 07:58 AM

probably a path problem.
but first, if you start your script with sh: sh <path>/<yourscript> you would not need #!/bin/bash at the beginning (not to speak about that sh and bash are not the same, so you would also need to select which one to use.
Insert a line into that script, for example touch <somefile> to check if it started (if that file was created or not). Use full path to msmtp, proably it was not found

NozeDive 04-11-2013 10:19 AM

Thank you Pan64 for the reply. I had no idea about the sh and bash thing you mentioned. I believe you, but I'm surprised, since that's how I was taught in my Intro to Linux class a few quarters ago. Although, admittedly, the instructor for that course was not very familiar with Linux.

So I modified the script to follow your advice. I added the full path, and then I also added a line to touch the file touchme. (I created the file touchme, and then changed its permissions to 777. Then, for good measure, I changed that script to write date and time info to a different file than the configuration file for the motion daemon, so that I'd know which entity (the motion daemon, or my script) is writing the date and time.

Here's sendtony.sh

Code:

#!bin/bash
echo date >> /etc/motion/bleh.txt
touch /etc/motion/touchme
/usr/bin/msmtp -t < tonymsg

It's supposed to write date and time to bleh.txt, update the timestamp of touchme, and send the contents of tonymsg via msmtp

AH HAH! Now we are getting somewhere! If you look at the contents of /etc/motion, it becomes evident that the motion daemon is performing the command to write date and time on motion, but not calling the script (or it is calling it, but it cannot execute).

Code:

drwxrwxrwx  2 root  root    4096 Apr 11 10:41 .
drwxr-xr-x 68 root  root    4096 Apr 11 05:36 ..
-rw-r--r--  1 motion motion  2668 Apr 11 10:42 blarg.txt
-rw-r-----  1 root  motion 24272 Apr  3 13:35 motion.conf
-rwxr-xr-x  1 tony  tony    139 Apr 11 10:45 sendtony.sh
-rw-r--r--  1 root  root    2385 Apr  3 13:20 thread1.conf
-rw-r--r--  1 root  root    2548 Apr 11 10:45 thread2.conf
-rw-r--r--  1 root  root    2110 Aug 10  2010 thread3.conf
-rw-r--r--  1 root  root    2625 Aug 10  2010 thread4.conf
-rwxr-xr-x  1 tony  tony    152 Apr 10 15:36 tonymsg
-rwxrwxrwx  1 root  root      9 Apr 11 10:39 touchme

Notice that the timestamp on touchme is 10:39, but I restarted the motion daemon at 10:42.

Here's the output of blarg.txt that shows that the motion daemon did detect motion, and executed the first instruction

Code:

Thu Apr 11 10:42:27 EDT 2013
Thu Apr 11 10:42:27 EDT 2013
Thu Apr 11 10:42:28 EDT 2013
Thu Apr 11 10:42:28 EDT 2013
Thu Apr 11 10:42:34 EDT 2013
Thu Apr 11 10:42:34 EDT 2013
Thu Apr 11 10:42:35 EDT 2013
Thu Apr 11 10:42:35 EDT 2013
Thu Apr 11 10:42:36 EDT 2013
Thu Apr 11 10:42:36 EDT 2013
Thu Apr 11 10:42:37 EDT 2013
Thu Apr 11 10:42:37 EDT 2013
Thu Apr 11 10:42:38 EDT 2013
Thu Apr 11 10:42:38 EDT 2013
Thu Apr 11 10:42:39 EDT 2013

Also, notice the absence of bleh.txt. sendtony.sh should have written that file as well.

So I was again stumped, but then thought that perhaps in the config file, I should take out the second on_motion_detect directive, since maybe it was overriding the second one, and it was! So no, when there is motion detected, the motion daemon executes the sendtony.sh script, which does write the date and time, and does update the time stamp of touchme, but still does not send the email. :-(
Code:

root@debian-tony-server:/etc/motion# ls -l | grep bleh && ls -l | grep touch
-rw-r--r-- 1 motion motion    58 Apr 11 11:03 bleh.txt
-rwxrwxrwx 1 root  root      9 Apr 11 11:03 touchme

(The time stamps have updates, indicating that the script is in fact called by the motion deamon)

So, well, I'm pretty stumped again.

pan64 04-12-2013 12:18 AM

so you can also try to insert the following line:
exec 2>> /etc/motion/error.log
And hopefully you will get some error message


All times are GMT -5. The time now is 05:30 PM.