0

I'm writing a little script to use the webcam on the laptop and then email across the photo to me. The ffmpeg usage has to have a exit code for it to work so with this exit the mail function will not get called. What am I doing wrong?

#!/bin/bash

[email protected]
ts=`date +%s`
list=$(ls | tail -n 1)

function mcheese(){
mkdir /tmp/cheese
cd /tmp/cheese
echo -e "Cheese " | mutt -s "$TS Cheese" $MAIL_ADDR -a $list
}

function cheese(){
ffmpeg -f video4linux2 -s vga -i /dev/video0 -vframes 3 /tmp/cheese/vid-$ts.%01d.jpg 
exit 0
}

cheese
mcheese
7
  • 1
    So what happens when you simply remove that exit 0 ? Note that you can return 0 from a function without exiting the whole script. Commented May 2, 2013 at 13:19
  • If you need the exit, can it be in a subshell? For example, $(ffmpeg ... ; exit 0).
    – gpojd
    Commented May 2, 2013 at 13:20
  • error when exit is removed - Can't stat yasm-1.1.0.tar.gz: No such file or directory yasm-1.1.0.tar.gz: unable to attach file.
    – Grimlockz
    Commented May 2, 2013 at 13:21
  • where does this yasm-1.1.0.tar.gz file appear? Commented May 2, 2013 at 13:22
  • in the root of the folder - so for this its /home/user/scripts/yasm-1.1.0
    – Grimlockz
    Commented May 2, 2013 at 13:23

1 Answer 1

1

You setup list in one directory, then change directory and use it. This is unlikely to work.

Use bash -x to work out where your script is actually failing.

2
  • Ahh silly me - I was listing the root folder - working now :-)
    – Grimlockz
    Commented May 2, 2013 at 13:40
  • @Grimlockz you can use this little trick to avoid problems when changing directories: list=$(ls -d "$PWD"/* | tail -n 1). That way it will have the full path. Commented May 2, 2013 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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