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


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?

  • Why do you use sudo on the second line ? Presumably your script runs under user pi right ? – Anonymous Apr 27 at 14:11
  • @Anonymous yes, i think that the only option is, if its even possible, to log on to my pi at the motion user, rather than the pi user – Fabio G Apr 27 at 15:54

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
| improve this answer | |
  • same error with sudo -u pi ls. For sudo on_movie_end /home/pi/motion/drop/dropupl.sh, this is not the correct way to exectute on_movie_end – Fabio G Apr 27 at 18:39
  • @FabioG On my RasPi the command runs flawlessly. It seems the problem is your sudo installation. Please check what's wrong with your sudo. Executed on the commandline the command must run without messages, just returning the files list in the current directory. – Ingo Apr 28 at 8:23

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.

| improve this answer | |
  • Doesn't work with all these options, still the same error :( – Fabio G Apr 28 at 19:17
  • What have you done exactly ? I suggest that you log in as user motion (type this as root): su - motion. Then trying to run your script as user motion and see what happens. This is the best way to debug the issue. Did you remove sudo from the second line ? The point that I suggested is to run the whole script as user motion, but set appropriate permissions on the directories where video files are saved. I recommend that you create a new directory and grant read+write access to both users pi and motion. – Anonymous Apr 28 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.