You are not logged in.

#1 2012-02-04 01:44:41

sweetthdevil
Member
Registered: 2009-10-20
Posts: 417

loop command timed to carry on unless error,

Hi all,

I am using ffmpeg with a time command, I want it to record x amount of second the video input. Therefore I want that command to go on indefinitely unless it failed, then I want the script to execute another command.

But if I use the done after the command it will move to the next command, how to have that command repeated and then move to the following one if it failed?

many thanks for your time and for your input,

Regards,

Offline

#2 2012-02-04 02:16:07

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: loop command timed to carry on unless error,

Not sure if I get what you want to do, but maybe try break / continue: http://tldp.org/LDP/Bash-Beginners-Guid … 09_05.html

Offline

#3 2012-02-04 02:26:46

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 239
Website

Re: loop command timed to carry on unless error,

i'm not sure, if I understood you correctly. Do you want something like this?

while true; do
    ffmpeg foobar
    if [ $? -ne 0 ]; then # $? contains the exit status of last command
        break  # exit loop when ffmpeg failed
    fi
done
other command

or if the loop should continue if ffmpeg failes:

while true; do
    ffmpeg foobar
    if [ $? -ne 0 ]; then
         other command
    fi
done

Offline

#4 2012-02-04 02:43:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: loop command timed to carry on unless error,

No need for  the if blocks, just put the test in the while condition.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB