Friday, 23 August 2013

Cron fails the script command

Cron fails the script command

I am trying to capture a picture with my webcam and I need to log the
output to check for errors, but cron is failing at this. I am able to do
this from terminal, but cron running it doesn't work.
Here's the script:
#!/bin/bash
script -ac "fswebcam -c /home/webcam/webcam.conf"
/data/webcam/logscript.txtCrontab:
@reboot mv /home/webcam/tmp/* /home/webcam/tmp_lost/
* * * * * sh /data/webcam/script.sh > /data/webcam/log.txt 2>&1
Terminal output:
[webcam@raspberry-pi webcam]$ sh /data/webcam/script.sh
Script started, file is /data/webcam/logscript.txt
--- Opening V4L2:/dev/video0...
/dev/video0 opened.
Setting Brightness to 0 (50%).
Setting Contrast to 19 (20%).
--- Capturing frame...
Skipping 50 frames...
Timed out waiting for frame!
Capturing 1 frames...
Timed out waiting for frame!
Captured frame in 0.00 seconds.
No frames captured.
Script done, file is /data/webcam/logscript.txtlogscript.txt (generated by
script command) when ran from terminal:
[webcam@raspberry-pi webcam]$ cat logscript.txt
Script started on ke 21. elokuuta 2013 21.10.52
--- Opening V4L2:/dev/video0...
/dev/video0 opened.
Setting Brightness to 0 (50%).
Setting Contrast to 19 (20%).
--- Capturing frame...
Skipping 50 frames...
Capturing 1 frames...
gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts
with 0xba 0x28
Captured 51 frames in 3.91 seconds. (13 fps)
--- Processing captured image...
Flipping image horizontally.
Flipping image vertically.
Putting banner at the bottom.
Setting banner background colour to #FF000000.
Setting banner line colour to #FF000000.
Setting banner text colour to #FFFF00.
Setting font to luxisr:12.
Setting timestamp "%d.%m.%Y %H:%M".
Writing JPEG image to '/home/webcam/tmp.jpg'.
Script done on ke 21. elokuuta 2013 21.10.57Running it through cron. Cron
output -> log.txt
[webcam@raspberry-pi webcam]$ cat log.txt
Script started, file is /data/webcam/logscript.txt
Script done, file is /data/webcam/logscript.txt
--- Opening V4L2:/dev/video0...
/dev/video0 opened.
Setting Brightness to 0 (50%).
Setting Contrast to 19 (20%).
--- Capturing frame...
Skipping 50 frames...
Capturing 1 frames...
gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts
with 0x8e 0x80
Captured 51 frames in 3.38 seconds. (15 fps)
--- Processing captured image...
Flipping image horizontally.
Flipping image vertically.
Putting banner at the bottom.
Setting banner background colour to #FF000000.
Setting banner line colour to #FF000000.
Setting banner text colour to #FFFF00.
Setting font to luxisr:12.
Setting timestamp "%d.%m.%Y %H:%M".
Writing JPEG image to '/home/webcam/tmp.jpg'.
Script started, file is /data/webcam/logscript.txtlogscript.txt file is
empty after cron and that is the problem. As you can see: when running
from cron, the script-command is started and done'd before any output
happens. When in terminal it is fine. Anyone know why this is happening?

No comments:

Post a Comment