1

i'm trying to configure motion in raspbian.

All works good but i have some problems with on_movie_end, this is the command:

on_movie_end /home/pi/motion/drop/dropupl.sh

this is a script that upload a video in my dropbox account. This is the content

#!/bin/bash

echo "start upload" >> /home/pi/motion/drop/log.txt
sudo -u pi /home/pi/motion/drop/dropbox_uploader.sh upload /home/pi/motion/detected/02-25042020212043.mp4 test7.mp4 >> /home/pi/motion/drop/log.txt 2>&1
echo "end upload" >> /home/pi/motion/drop/log.txt

and this the content of the log file

start upload

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified
end upload

from the command line /home/pi/motion/drop/dropupl.sh works, uploads the video on dropbox and it writes on the log file.

But when a motion is detected it writes on the log file but it 'skip' the line with the command and it doesn't upload the video on dropbox.

How can i fix this?

Fabio G
  • 11
  • 1

2 Answers2

1

The message about "three things" is from sudo if you start it the very first time after installation. Then you have to enter the users password only this one time and was never asked again if configured. On default Raspbian this has already be done so I do not understand why do you get this question. Then there is another issue with the message: sudo: no tty present and no askpass program specified. It means there is no terminal available within the script environment to ask for the password so it will always ask again.

I suggest to answer the question of sudo just the first time with:

rpi ~$ sudo -u pi ls

Then you should see the "three things" and can enter the password. Sudo should never ask again. It may also be a problem to run sudo inside the script because of missing a needed environment. Try to run it without sudo, or if really needed then call the script with sudo but not within the script:

sudo on_movie_end /home/pi/motion/drop/dropupl.sh
Ingo
  • 42,961
  • 20
  • 87
  • 207
0

From the Motion doc:

When running as a service, Motion runs as the user motion and this user is automatically added to the user group of video. By only be included in this user group, when Motion is run, it will only have limited permissions. It is NOT recommended that this user get added to the sudo group. Instead, only add this user to groups that are specifically required.

So one possibility is setting up ad hoc permissions on the script using the setfacl command so that the Motion user has execute permissions on the script - See Give specific user permission to write to a folder using +w notation

So in your case that would be something like:

setfacl -m u:motion:rwx /home/pi/motion/drop/dropbox_uploader.sh

But this for the script only, it still needs access to the video files. Granting access to the whole pi home directory is not a great idea but here's how to do it. This is the quick and dirty way.

The best imo would be to do everything under the motion username. First check if the user already has a directory in /home. If it doesn't exist, create it: useradd -m motion (add home directory for existing user). Then run your scripts with user motion instead of pi.

To login as user motion type this as root: su - motion. Then you can also define cron jobs for that user etc.

If you want to have both users pi and motion have access to the same files I would suggest:

  • create a new group
  • add both users to that group
  • create a new directory
  • grant ownership of the directory to the group

This will avoid messing with the permissions on the pi home directory.

Kate
  • 304
  • 2
  • 5