In the spirit of my memento-mori.sh, I’ve written a script to sleep randomly 0-10 minutes and take a screenshot & webcam shot. Obviously many of the values are specific to my own computer (such as the names in /proc, where in ~/ the pictures are sent to, and the use of ImageMagick, jpegoptim, and OptiPNG), but it should be easy to adapt to your own computer:
#!/bin/sh
set -e
if grep open /proc/acpi/button/lid/LID?/state > /dev/null
then
CURRENT=`date +%s`;
SLEEP=$(( $CURRENT % 10 ))
TIMEOUT="m"
sleep $SLEEP$TIMEOUT
import -quality 100 -window root png:$HOME/photos/webcam/xwd-$CURRENT.png
fswebcam --resolution 1280x1024 -S 2 -F 3 ~/photos/webcam/$CURRENT.jpg
optipng -o9 -fix `ls -t ~/photos/webcam/*.png | head -1`
jpegoptim -m50 `ls -t ~/photos/webcam/*.jpg | head -1`
fi
My original script ran every hour on the hour, but I discovered that this was so predictable that I was beginning to work-around it by switching to a more kosher good-looking application, and wasn’t frequent enough anyway. Hopefully the randomized version will work better.
Thank you for posting this. I want to do almost exactly this, and set up another task running that will zip up all the images and send them off to my referee.
Unfortunately, I haven’t gotten this to work. I’m not very familiar with cron, and I don’t know how to debug it. My script works as intended when run manually, but halts (dies? I don’t know) when run from cron (at import). I haven’t managed to get any error reporting, either by redirecting the script output or the import output. I also haven’t been able to get import to run directly from cron, even by using absolute paths and no variables. I suspect these are problems you haven’t run across, but if you have, I’d appreciate your advice.
Cron does its error reporting through local email, so when I’m debugging, I’d check /var/mail/gwern. You may need to’ve chosen ‘local delivery’ when configuring your install on a Debian system.
In the spirit of my memento-mori.sh, I’ve written a script to sleep randomly 0-10 minutes and take a screenshot & webcam shot. Obviously many of the values are specific to my own computer (such as the names in
/proc
, where in~/
the pictures are sent to, and the use of ImageMagick,jpegoptim
, and OptiPNG), but it should be easy to adapt to your own computer:This would be called from one’s
crontab
like so:My original script ran every hour on the hour, but I discovered that this was so predictable that I was beginning to work-around it by switching to a more kosher good-looking application, and wasn’t frequent enough anyway. Hopefully the randomized version will work better.
Thank you for posting this. I want to do almost exactly this, and set up another task running that will zip up all the images and send them off to my referee.
Unfortunately, I haven’t gotten this to work. I’m not very familiar with cron, and I don’t know how to debug it. My script works as intended when run manually, but halts (dies? I don’t know) when run from cron (at import). I haven’t managed to get any error reporting, either by redirecting the script output or the import output. I also haven’t been able to get import to run directly from cron, even by using absolute paths and no variables. I suspect these are problems you haven’t run across, but if you have, I’d appreciate your advice.
Cron does its error reporting through local email, so when I’m debugging, I’d check
/var/mail/gwern
. You may need to’ve chosen ‘local delivery’ when configuring your install on a Debian system.