Cron falha no comando de script

0

Estou tentando capturar uma imagem com minha webcam e preciso registrar a saída para verificar erros, mas o cron está falhando com isso. Eu sou capaz de fazer isso a partir do terminal, mas a execução do cron não funciona.

Aqui está o script:

#!/bin/bash
script -ac "fswebcam -c /home/webcam/webcam.conf" /data/webcam/logscript.txt

Crontab:

@reboot mv /home/webcam/tmp/* /home/webcam/tmp_lost/
* * * * * sh /data/webcam/script.sh > /data/webcam/log.txt 2>&1

Saída do terminal:

[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.txt

logscript.txt (gerado pelo comando de script) quando executado do 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.57

Executando através do cron. Saída Cron - > 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.txt
O arquivo

logscript.txt está vazio após o cron e esse é o problema. Como você pode ver: ao executar a partir do cron, o script-comando é iniciado e feito antes de qualquer saída acontecer. Quando no terminal está tudo bem. Alguém sabe por que isso está acontecendo?

    
por Miikka 21.08.2013 / 20:18

1 resposta

0

Quando chamado como sh /data/webcam/script.sh > /data/webcam/log.txt 2>&1 , sh interpretará /data/webcam/script.sh como um arquivo de comando e tudo o mais como argumento para ele - incluindo, possivelmente, os operadores de redirecionamento.

Força sh a interpretar '/data/webcam/script.sh > /data/webcam/log.txt 2>&1' como um comando:

sh -c '/data/webcam/script.sh > /data/webcam/log.txt 2>&1'

    
por 21.08.2013 / 20:52