2

I have created a shell script to capture images every minutes on my raspberry pi. I think something is not quite right as it has been taking pictures but not saves them. I wonder if someone could just point out if this script should work:

#!/bin/bash
DATE=$(date +"%Y-%m-%d")
TIME=$(TIME +"%H%M%S")
if[! -d /media/pi/organ/$DATE]; then mkdir /media/pi/organ/$DATE; fi
raspistill -vf -ISO 100 -o /media/pi/organ/$DATE/$TIME.jpg

Additional info: raspistill -vf -ISO 100 -o /media/pi/organ/$DATE.jpg worked

I also added crontab to run every minutes and that worked too:

* 8-20 * * * /home/pi/camera.sh 2>&1

My concern was to leave it for more than 4 weeks so the amount of files would exceed the limit of a folder so I tried to break it down.

When I added this script it stopped working and I don't know how to troubleshoot from here.

5

In this line:

TIME=$(TIME +"%H%M%S")

you set the variable time to the output of a command TIME invoked with +"%H%M%S" as argument.

AFAIK there is no command TIME on the RaspberryPi. You should change that to:

TIME=$(date +"%H%M%S")
2

There are some errors in the syntax, and I think you meant date in the assignment of the variable TIME. Here is my suggestion:

#!/bin/bash

DATE=$(date +"%Y-%m-%d")
TIME=$(date +"%H%M%S")
OUTDIR="/media/pi/organ"

if [ ! -d "${OUTDIR}/${DATE}" ]
then 
    mkdir -p "${OUTDIR}/${DATE}" 
fi
raspistill -vf -ISO 100 -o "${OUTDIR}/${DATE}/${TIME}.jpg"

The -p of mkdir also creates the parent directories, otherwise the script will fail if the parent directories are not present. It is also good parctice to cover variables that hold filesystem pathes with ". This is a nice overview and worth to read it if you want to do more in shell scripting.

In general, adding a set -x at the beginning of your script will also print more information to debug things.

  • 2
    if you are using -p option of mkdir, then why not skip test of directory existence ? – Archemar Mar 20 '16 at 13:38
  • Yes, true. One could just replace the whole if statement with a single mkdir -p "${OUTDIR}/${DATE}". – Thomas Mar 20 '16 at 14:09
1

Break your problem down and solve it in pieces. First, get the command that takes the photo and saves it working.

How do you know it is taking a photo? Have you tried saving it to a well known and writable place like a test directory in your own home directory? You are running a command that seems to have -v as an option, which looks a lot like a verbose setting. Spend some time looking at the output of the command because it is probably telling you why it can't do everything you are asking.

Only then try to make it automatic. Don't use a script for this. Use something like cron

The key is do this in increments.

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.