I wrote a bash script that uses the dropbox app as per RaspiTV. I am using a standard USB webcam and streamer to capture videos of my cat when I am away from home with the hope that these can be uploaded to my dropbox account.

the script that does this and works just fine when run manually is:

streamer -t 0:0:15 -c /dev/video0 -f rgb24 -r 3 -o /home/pi/Downloads/$(date +%m%d_%H%M%S).avi
fn=`echo $(ls *.avi -t | head -n1)`
echo $fn
/home/pi/Dropbox-Uploader/./dropbox_uploader.sh upload $fn /catcamFolder

Where catcamFolder is my folder on Dropbox where the .avi files are deposited.

When I run my script manually from command line such as: ./myscript.sh, it runs beautifully and I have the video file depo'd in my dropbox.

However, when I try to cron it using the following crontab -e script, nothing happens, the file is neither generated not deposited in dropbox:

1,15,30,34,45 7-21 * * * /home/pi/Downloads/myscript.sh

So... this crontab line runs myscript.sh at minute 1,15,34,45 from 7am-9pm every day.

What am I doing wrong that the script doesn't run through cron but runs fine by itself? I hope I get help so that I can keep an eye on my feline friend!

By the way, the line of bash script: fn=echo $(ls *.avi -t | head -n1) provides the name of the most recent .avi file. This bit of useful information was from another SE


The following call contains a relative path *:

fn=`echo $(ls *.avi -t | head -n1)`

Use absolute paths:

fn=`echo $(ls /home/pi/Downloads/*.avi -t | head -n1)`

The script will not work even interactively if your current directory is not /home/pi/Downloads.

Other remarks:

  • in this case the above will work, but generally you shouldn't parse the output of ls at all (read this).

  • if you decide to parse ls you should at least quote fn variable in the call:

    /home/pi/Dropbox-Uploader/./dropbox_uploader.sh upload "$fn" /catcamFolder

    Again: it's not a direct reason for the problem, but the script will break if files contained spaces.

  • echo is superfluous in the following assignment:

    fn=`echo $(ls *.avi -t | head -n1)`

    It is the same as:

    fn=$(ls *.avi -t | head -n1)
  • Current directory is /home/pi/downloads. i.e. the videos are created in /home/pi/downloads and uploaded from here. Is that not what it is? Am I missing something? – dearN Dec 7 '16 at 1:53
  • No, current directory for the script executed by cron is not what you claim. – techraf Dec 7 '16 at 1:54
  • I apologize but I have am slow so it is a little tough for me to understand multiple dependencies. You mean that the dropbox_uploader.sh script should be in the current directory? Again, thank you for your input. – dearN Dec 7 '16 at 1:56
  • Thank you. I appreciate your answer and subsequent edits. I'll try it out now and see how things go. – dearN Dec 7 '16 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.