Raspberry Pi Motion on_motion_detected not running gphoto2 script - bash

I'm trying to get Motion to trigger gphoto2 with on_motion_detected.
I can get this event to run a bash script, I can get it to run a python script. If either of those calls gphoto2 it fails.
Running the bash scrip or python script from the command line works. So the problem is probably something that is too in the weeds for me to figure out. Over on Reddit, a user with a similar problem found a solution by adding Motion as a user to the plugdev group. I tried that, but it didn't work for me.
https://www.reddit.com/r/raspberry_pi/comments/cqnuqh/help_gphoto2_and_motion_as_camera_trigger/
in motion.conf:
on_motion_detected /bin/bash /home/pi/Scripts/script.sh
and the script:
#!/bin/bash
gphoto2 --capture-image
Motion is using a Raspberry Pi Camera Module 2, and I'm trying to trigger a Sony A7Rii with gphoto2. Again, each works on its own separately, just not together.

Related

Raspberry Pi pico script exeucte kill

I wrote a script with the while loop command and I executed it on my Raspberry Pi, however I didn't put a break in it, so it won't stop. I tried to interrupt it, but the script is still being executed. I used thonny Python and I tried to exit it, Ctrl+C, soft reboot. I even tried to put it in storage mode and reset it, but it's still being executed. I'm trying to work out how to completely delete the script from the pico itself. Do you have any ideas?
Python:
from machine import Pin
from time import sleep
led = Pin(25, Pin.OUT)
while True:
led.toggle()
sleep(0.5)
I'm reasonably sure that RPiOS has a task manager, so you could try killing it in that.
If it doesn't then open up your terminal and run ps -ef to find the PID of the python process (it should show the name of the command). Then run sudo kill -9 <PID> to kill it manually.
Edit:
I now understand that the RPi Pico is actually a microcontroller. Have you tried uploading a new program or just unplugging it from power to force it to reboot?

bash/python consequtive commands in a nested environment

I have a task for my thesis which includes a camera and several LEDs and they can be controlled by some bash commands. To access the system, I need to run ssh root#IP and access the default path of the system. Under this path there is a script which opens the camera application by running ./foo and once it is executed, I am inside the camera application. Then, I can check the temperature of the LED's etc by typing i.e. status -t
Now my aim is to automatize this process to check the temperature by a bash script or python code. In Bash, If I run i.e ssh root#192.168.0.1, ./foo and status -t consecutively, I can get the temperature value. However, executing ssh root#192.168.0.1 './foo' 'status -t, ends in a infinite loop. If I do ssh root#192.168.0.1 './foo', I expect to be in camera application but this opens the application weirdly such that I can't execute status -t afterwards.
I tried also something like this
ssh root#192.168.0.1 << EOF
ls
./foo
status -t
EOF
refer to
or in python using subprocess ssh using python and with paramiko.
but nothing really works. What actually differs my situation from the rest of these examples is that my commands depend on each other, one opens another application and run the next command in the next application.
So the questions are
1- Does what I am doing make sense and is it even possible?
2- How to apply is in a script/python code?

How to run python code in rapberry pie in background after boot-up and reboot?

I want to to run my program as soon as raspberry pi boot-up or restart. I've tried $contab -e and added program but in log it showed it started but no output nothin. I've to run it manually everyday using $nohup ./Code &
even tried adding the run command in /etc/rc.local with full path.
How can I run the program then. It's working very well and gives output at normal run.

How to run screen using bash script

I am developing an application on Linux CentOS server. I need to automatically after registration of each use server create a screen to run some codes in loop for user.
When I use bash script to create new screen, it can't open screen and run commands in that screen.
For example, I want to open an screen and I run a php file in that screen. I have created a bash script test.sh but when I run this using cron tab it doesn't work.
screen
php php.php
Please tell what can I do to solve this?
It's quite easy to do this and such a thread already exists.
screen -d -m yourcommand

Hudson-CI launched screen session terminates when task ends

The main problem I'm having is to background a screen session from Hudson-CI. The shell steps are that I need to start a screen session from a script that is launched by another script. Heres' a simple test:
test.sh:
#!/bin/bash
myscreen.sh
myscreen.sh:
#!/bin/bash
screen -dm -S myscreen pingit.sh
pingit.sh:
#!/bin/bash
ping google.com
If I run ./myscreen.sh I get a screen launched that runs the ping continuously without a problem.
If I run ./test.sh, the screen is never started. I'm assuming there's something basic that I'm either forgetting or not understanding, but I can't figure out what. I thought this would work.
The real reason I want to do this is to have Hudson CI launch a continuous-test script which starts as a screen session so that it can continue in the background. What I'm finding is that the screen session terminates once the task is completed in Hudson.
Any ideas on why I can't launch a persistent screen session from a grand-parent script? Or any ideas on how to deal with this?
This is on OSX 10.6, with screen built from source (so it should work the same as linux I think).
If I run your test.sh, I get the error message
./test.sh: Zeile 2: myscreen.sh: Kommando nicht gefunden.
i.e. command not found. You'll have to write ./myscreen.sh, if the current directory is not on the path. (Is it for you? It should not.) The same is valid for the screen call.
Changing both files to
#!/bin/bash
./myscreen.sh
and
#!/bin/bash
screen -dm -S myscreen ./pingit.sh
I can start my screen without any problems.
I'm on Linux (OpenSUSE) with
$ screen --version
Screen version 4.00.03 (FAU) 23-Oct-06
here.
I don't know why I did not find the following references before, but these were the links that helped me solve the problem:
https://serverfault.com/questions/155851/run-gnu-screen-from-script
http://wiki.hudson-ci.org/display/HUDSON/Spawning+processes+from+build
There are 2 issues here - one of screen being persisted after being launched by a grand-parent process. The other that hudson terminates a session after it completes its task.
The screen problem is resolved by zombie'ing the process as follows:
screen -d -m -S myscreen && screen -S myscreen -X zombie qr && screen -S myscreen -X screen pingit.sh
The Hudson-CI problem turns out to be a bug that's easily resolved per the above link. The solution is to add BUILD_ID=something into the shell script. So if the test.sh script from above is actually the Hudson Build shell execute, then it would have to be changed to:
#!/bin/bash
BUILD_ID=dontkillthisprocess
myscreen.sh
Once both of these steps are implemented, things work fine.

Resources