?

Log in

No account? Create an account

Previous Entry | Next Entry

Gah!

Okay, I am stuck on something, and maybe some of you know how to write shell scripts for this?

I want to set things up so I can grab images from the webcam for scheduled time periods. I found a cute little shell script that pointed me in the right direction:

#!/bin/bash
while [ true ]; do
filename=$(date +"%Y%m%d_%H%M%S").jpg
wget http://192.168.x.x/jpg/image.jpg -O $filename
sleep 5s;
done;

But how do I actually set things up so that I collect images from, say 1 am to 2 am? (I don't want to have to come to the lab to run this at that time if I can help it).

Comments

( 7 remarks — Remark )
randomdreams
Apr. 23rd, 2016 05:23 am (UTC)
If this is linux, I'd look at setting up either a cron job (for older systems) or writing a systemD service script (for newer systems.)

http://stackoverflow.com/questions/8938120/how-to-run-cron-once-daily-at-10pm

https://wiki.archlinux.org/index.php/Systemd/Timers

It appears you can set up cron jobs on even newer systems, and they are somewhat easier in many ways.
tylik
Apr. 23rd, 2016 10:56 am (UTC)
This is pretty much what I was going to write.
scrottie
Apr. 24th, 2016 08:23 am (UTC)
Almost anything I'd do in bash, I do in Perl instead, so I'm a bit rusty here... but, you probably want this:

if [ `date +"%H"` == "01" ];then echo ok;fi

Or:

if [ `date +"%H"` == "01" -o `date +"%H"` == "02" ];then echo ok;fi

Replace "echo ok" with the filename=...;wget;sleep 5s stuff.

http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

http://linux.die.net/man/1/test

cron is an alternative if it doesn't need to run more than once a minute. It looks like you want to run every five seconds though.
rebeccmeister
Apr. 24th, 2016 06:33 pm (UTC)
Thanks!

It might wind up being the case that none of this matters much, because it looks like BioTracker works best with videos that have ~2.5 frames per second, and contrary to some of what I was reading, 'sleep' doesn't like fractional seconds. Which all means I might need to look into using some form of video capture instead...although maybe I'll be back at command line methods for scheduling video capture pretty quick.

I was working on that form of syntax, but then my brain didn't want to sort out the details of how to deploy the correct format for time.
rebeccmeister
Apr. 25th, 2016 11:51 pm (UTC)
Woo, this looks like it will work, yay!
scrottie
Apr. 26th, 2016 04:03 am (UTC)
The one problem I see with this is you won't exactly get an image every three seconds. `sleep` promises to sleep at least the amount of time specified but will go a few milliseconds over, and that doesn't include the time `wget` takes which can be several milliseconds easily (or longer on a slow site or network). So you'll likely wind up with about one image every 3.1 seconds or so.

The fix involves doing a little math... and likely rewriting it in Python or R or Perl or something. That is, if that actually matters.
rebeccmeister
Apr. 26th, 2016 04:10 am (UTC)
And I also thought about it some more and actually I will probably have to use chron or 'when' instead of 'if...fi'
( 7 remarks — Remark )

Latest Month

November 2017
S M T W T F S
   1234
567891011
12131415161718
19202122232425
2627282930  

Tags

Powered by LiveJournal.com
Designed by Naoto Kishi