?

Log in

No account? Create an account

Previous Entry | Next Entry

Stuck point again

After another day of muddling along on the cricket video project, let's see.

I figured out that I needed to be using Cygwin with admin permissions, so that helped. I reran cron-config, and then set up my crontab thus (after fiddling around for a little while to sort out the vim editor, which for some reason didn't behave in the same fashion as when creating and editing a shell script):

* * * * * echo "Cron test at $(date +\%k:\%M)" >> /cygdrive/c/Crontest.txt 2>&1

(can anyone tell me what the 2>%1 at the end of the line is doing??)

With this, if I type in "net start cron," this will write to a text file on the C drive every minute, which is a nice test. Of course, this also required some head-scratching to learn that the method for escaping the little Cygwin universe is to put "/cygdrive/c/" in front of the file destination.

But what I actually want to do is run a shell script and then deposit the contents in a directory.

My test shell script is as follows:

#!/bin/bash
FRAMES=1
while [ $FRAMES -le 4 ]
do
filename=$(date +"%Y%m%d_%H_%M_%S").jpg
wget http://www.acromyrmex.net/rebeccaheadshot.jpg -O $filename
FRAMES=`expr $FRAMES + 1`
sleep 5s
done

In a nutshell (help! I'm in a nutshell!), this goes to my website and grabs my picture 4 times and saves it with 4 timestamps.

But when I tried to test this by appending a second line to my crontab file:

40 13 * * * /TestingScripts/TestTimeGrab.sh >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/ 2>&1

Nothing happened. I suspect I'm not asking it to run the shell script correctly, or there's something else that's weird going on. I could check "cronevents" to see if there are any hints, if that's helpful.

This all seems like it should be so straightforward to do, but, as discussed with scrottie, it kind of involves a combination of dealing with annoying aspects of Windows PLUS annoying aspects of Unix, plus me having to learn my way around the vim editor and Cygwin peculiarities.

On the other hand, if I can get this configuration all sorted out, I'll be well on my way to getting some video collected so I can see how bad things are going to get with BioTracker. And, having done that part of things, I'll be nicely set up to start collecting lots of useful and interesting behavioral data.

In the meantime, I think I'm going to plug away at something that's a little more straightforward today - namely, measuring the carbohydrate content of cricket blood (hemolymph).

Tags:

Comments

( 6 remarks — Remark )
rebeccmeister
Apr. 28th, 2016 04:52 pm (UTC)
Editing crontab versus shell scripts
When I edit a shell script, if I press "i" to go into "insert" mode, I can then navigate around using the arrow keys. The crontab file won't let me do this, so I had to get used to using hjkl to navigate and to using other keyboard commands to edit the file. Not impossible, but why the difference? I blame cron.
scrottie
Apr. 28th, 2016 09:15 pm (UTC)
Re: Editing crontab versus shell scripts
Try this command in vim and see if it fixes it:

:syntax off

(Anonymous)
Apr. 29th, 2016 10:25 pm (UTC)
Re: Editing crontab versus shell scripts
Seems odd. Maybe try "$ env VISUAL=vim crontab -e" to enforce usage of vim (or whatever editor you prefer) when editing the crontab.
scrottie
Apr. 28th, 2016 09:15 pm (UTC)
Re:

40 13 * * * /TestingScripts/TestTimeGrab.sh >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/ 2>&1

Try putting quotes around the entire command:

40 13 * * * "/TestingScripts/TestTimeGrab.sh >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/ 2>&1"

I don't remember if cron gobbles up the rest of the line as the command or not, but that's probably just because I've avoided the issue for a long time by instinctively quoting things.

I'm a bit rough on this, but I think /TestingSripts/TestTimeGrab.sh needs to be /cygdrive/c/TestingScripts/TestingTimeGrab.sh.

That last 2>&1 on the end of the command I think is going to hide any errors from the cron error log. If you want the normal output and the error output both to go to /cygdrive/c/Users/rebecca/TestPhotoGrabs/, then you probably want this instead:

"(/TestingScripts/TestTimeGrab.sh 2>&1) >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/"

Or this would send only the normal output there, leaving errors to go to the cron log:

"/TestingScripts/TestTimeGrab.sh >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/"

But... you're sending errors to a directory. That won't work. It'll just not do anything with them, or the output, since you can't add text to a directory, only files and other directories, and it isn't smart enough to just start creating files in the directory. You probably want this:

"/TestingScripts/TestTimeGrab.sh >> /cygdrive/c/Users/rebecca/TestPhotoGrabs/test.log"

PATH may not e set in the cron and your script might not be able to find wget. You can do this at/near the top of the crontab file:

PATH=whatever

Get "whatever" from "echo %PATH%" in cmd.exe (but change the ; to :) or "echo $PATH" in bash. If there are spaces in the path (likely on Windows), you need quotes around the : separated list of paths. Eg:
PATH="/bin:/usr/bin:/home/Old Macdonald"

If errors start going somewhere, then figuring out that PATH isn't set (or whatever the actual problem is) will be much easier, so I'd do those bits first.
scrottie
Apr. 28th, 2016 09:20 pm (UTC)
Oh, as to what "2>&1" is doing... this is shell input/output redirection goop.

"2" is error output ("stderr"). 1 is normal program output ("stdout"). 0 is input ("stdin"), btw. Programs will open additional inputs and outputs, but all programs inherit those from the shell on Unix and always have them even if they don't do anything with them.

">&" means "redirect to the existing channel". In this case, it means "redirect error output to the existing output channel".

randomdreams
Apr. 29th, 2016 02:35 am (UTC)
This covers anything I would have said.
( 6 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