2016-07-27 109 views
1

我使用-wait-event-and-download参数运行gphoto,以便使用我的红外遥控器拍摄的照片保存到计算机中。获取gphoto2的当前状态

我有第二个脚本设置中断等待处理,并拍照编程,就像这样:

#!/bin/sh 
# shootnow.sh - stop the current gphoto2 process (if it exists), 
# shoot a new image, then start a new wait-event process. 

pkill -INT gphoto2  #send interrupt (i.e. ctrl+c) to gphoto2 
sleep 0.1    #avoid the process ownership error 
gphoto2 --capture-image-and-download #take a picture now 
gphoto2 --wait-event-and-download #start a new wait-event process 

但我想,以确保第一等待事件处理当前没有下载的图像在我中断它之前(这会导致图像填满相机的内存,妨碍进一步操作)的混乱情况。所以第二个脚本应该是更像这样的东西:

#!/bin/sh 
# shootnow-with-check.sh - stop the current gphoto2 process (if it exists 
# and isn't currently downloading an image), shoot a new image, then start 
# a new wait-event process. 

shootnow() { # same as previously, but now in a function 
    pkill -INT gphoto2 
    sleep 0.1 
    gphoto2 --capture-image-and-download 
    gphoto2 --wait-event-and-download 
} 

if [ ***current output line of gphoto2 process doesnt start with "Downloading"*** ] then 
    shootnow 
else 
    echo "Capture aborted - a picture was just taken and is being saved." 
fi 

任何人都可以帮助我,如果声明?我可以读取正在运行的gphoto进程的当前输出行吗?

+0

我期待使用'expect'先运行'gphoto -wait-event',然后监视“Downloading”字符串是否存在,当它发生时,将一些系统范围的变量(例如“ gphotoIsBusy“)设置为1,当检测到”Saving“字符串时再次将其关闭。任何人都知道如何让预期持续监控,像这样开启/关闭变量? – ajlowndes

回答

1

我最终与脚本管理这个像这样:

#!/bin/bash 
# gphoto2-expect.sh 
# use expect to monitor gphoto2 during --capture-image-and-download with 
# --interval=-1, adding in SIGUSR1 functionality except during a 
# download event. 

echo "Prepping system for camera" 
killall PTPCamera 
expect << 'EOS' 
puts "Starting capture..." 
if [catch "spawn gphoto2 --capture-image-and-download --interval=-1" gp_pid] { 
    Log $ERROR "Unable to start gphoto2.\n$gp_pid\n" 
    return 0 
} 

trap {exec kill -SIGUSR1 $gp_pid} SIGUSR1 
set timeout -1 
expect { 
    -i $spawn_id 
    "Downloading" { 
    trap {send_user "\n Ignoring request as currently downloading"} SIGUSR1 ; exp_continue 
    } 
    "Saving file as" { 
    sleep 0.1 
    trap {exec kill -SIGUSR1 $gp_pid} SIGUSR1 ; exp_continue 
    } 
} 

EOS 

这可能与其他脚本触发:

#!/bin/bash 
# trigger.sh - trigger an immediate capture 
var=$(pidof expect) 
kill -SIGUSR1 "$var" 
+0

注意。 pidof是一个自定义程序 - (显然)得到一个指定进程的PID。 – ajlowndes

1

gphoto2有一个选项--hook脚本文件名。 FILENAME必须是可执行的脚本,并在某些gphoto2事件上调用。然后该脚本具有一个可用于您的目的的环境变量ACTION。 例如:你叫gphoto2与

gphoto2 --capture-image-and-download --hook-script myhook.sh 

和myhook.sh看起来像

#! /bin/bash 
echo $ACTION 

然后myhook.sh将被称为4倍。它的输出是

init 
start 
download 
stop 

查看man gphoto2了解详情。

+0

我看了一下-hook-script,但最终发现它不适合我的目的,因为脚本只有在图像完成下载后才会调用。但是我需要检测gphoto2何时正在下载图像以决定是否允许中断。 – ajlowndes

+0

...但感谢您指出脚本必须是可执行的,我不知道。没有帮助我,但仍然有用。 – ajlowndes

+0

我使用选项--hookscript经常(和成功)等待下载的开始,它工作正常。 myHook.sh显示给你什么$ ACTION的内容? – mviereck

相关问题