Results 1 to 6 of 6

Thread: [SOLVED] Bash script help (background processes)

  1. #1
    Join Date
    Oct 2006
    Beans
    513

    [SOLVED] Bash script help (background processes)

    I'm having some problems with a simple script:
    Code:
    #!/bin/bash
    
    
    for f in *.ram ; do
    	url="$(cat $f)" # rtsp url
    #	echo mplayer -dumpstream $omg -dumpfile temp/$f\.rm \& ;
    	mplayer -dumpstream "$url"  -dumpfile temp/$f\.rm &;
    done
    
    wait
    When I run ./dl I get:
    Code:
    ./dl: line 7: syntax error near unexpected token `;'
    ./dl: line 7: ` mplayer -dumpstream "$url"  -dumpfile temp/$f\.rm &;'
    Is it not possible to start background processes inside a loop? If that's the case, what do I do?

    A typical .ram file looks like this:
    Code:
    rtsp://169.229.131.16:554//bibs/s2005/group1/ns10/20050119.rm?start=1:40&end=43:40
    Last edited by olejorgen; July 19th, 2007 at 12:52 AM.

  2. #2
    Join Date
    Jul 2007
    Location
    Idaho
    Beans
    23
    Distro
    Kubuntu 7.04 Feisty Fawn

    Re: Bash script help (background processes)

    I've run into this before, too, but I can't remember what I did. There is probably a clean elegant way to do it, but I'll offer the first hack that comes to mind. Build a string up through the loops (or append each command to a file) then after the loop execute it.

  3. #3
    Join Date
    Oct 2006
    Beans
    513

    Re: Bash script help (background processes) (SOLVED)

    Damn, I need to get better at searching. Found it on google: You have to put your commands inside {}.
    Code:
    #!/bin/bash
    
    
    for f in *.ram ; do
    	{ 
    		url="$(cat $f)" # rtsp url
    		mplayer -dumpstream "$url"  -dumpfile temp/$f\.rm & 
    	};
    #	echo mplayer -dumpstream $omg -dumpfile temp/$f\.rm \& ;
    done
    
    wait

  4. #4
    Join Date
    Jul 2007
    Location
    Idaho
    Beans
    23
    Distro
    Kubuntu 7.04 Feisty Fawn

    Re: Bash script help (background processes)

    And there is the clean way. Thanks for sharing, I'm sure I'll have that same problem again myself.

  5. #5
    Join Date
    Feb 2007
    Beans
    2,729

    Re: Bash script help (background processes) (SOLVED)

    Quote Originally Posted by olejorgen View Post
    Damn, ... you have to put your commands inside {}.
    Actually, you don't.

    The problem is that you have both ; and & terminating the line.

    Both ; and & are *line terminators*, therefore you only use one of them. What you have a a line followed by an empty command being backgrounded.

    You don't need semicolon's ending your shell commands. This would be sufficient:

    Code:
    for f in *.ram ; do
    		url="$(cat $f)" # rtsp url
    		mplayer -dumpstream "$url"  -dumpfile temp/$f\.rm & 
    done
    That said, it is generally a bad idea to startup lots of background processes all at once; they won't get done any faster, and will cause performance issues in general. If you know there won't be too many started, there's no issue. Just a caveat.

    MrC

  6. #6
    Join Date
    Oct 2006
    Beans
    513

    Re: Bash script help (background processes) (SOLVED)

    Thanks for the extra info

    I'm quite sure that mplayer is fecthing the stream at playback rate, so in this case it should be quicker. Wether this is nice (or even legal) to do is another question
    Last edited by olejorgen; January 13th, 2008 at 07:39 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •