Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Automation problem

  • 15-06-2011 3:29pm
    #1
    Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭


    This should be handy enough, but it's doing my noodle in.

    Let's say I have 12 files. 01.flac ..... 12.flac

    now let's say I want to oggenc them, but I want to kick off two instances simultaneously, one like this:

    oggenc -q8 01.flac 02.flac 03.flac 04.flac 05.flac 06.flac &
    and one like this:
    oggenc -q8 07.flac 08.flac 09.flac 10.flac 11.flac 12.flac

    How would you go about doing this in an automated way? (i.e. dividing the number of flac files in half for each command line). Remember, newlines and spaces make crap of everything.

    I can get the correct number of flac files to pass to each instance like this:

    NUMFLACFILES=`ls -1 *.flac | wc -l`
    HALF_NUMFLACFILES=$((NUMFLACFILES / 2))

    After that it gets messy. any attempt to use xargs prevents me from running stuff in the background.


Comments

  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    Are you just trying to split the processing up and take best advantage of your multiple processors?

    If so... this isn't exactly the answer you were looking for but a while back I used this small script to process the thousands of music files in my media collection to generate "moodbar" files for use in Amarok. I think it would be a very minor change to have have it do what you want, no? The scripts looks to see how many cores (or processors) you have spawns files so that all processors are kept busy.
    #!/bin/bash
        NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"
         
        find . -type f -regextype posix-awk -iregex '.*\.(mp3|ogg|flac|wma)' | while read i ; do
         
               while [ `jobs -p | wc -l` -ge $NUMCPU ] ; do
                       sleep 0.1
               done
         
               TEMP="${i%.*}.mood"
               OUTF=`echo "$TEMP" | sed 's#\(.*\)/\([^,]*\)#\1/.\2#'`
               if [ ! -e "$OUTF" ] ; then
                       moodbar -o "$OUTF" "$i" &
               fi
        done
    


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    croo wrote: »
    Are you just trying to split the processing up and take best advantage of your multiple processors?

    I am yeah. I'm impatient and I reckon I could halve the time, more or less. :) Thanks for that. I'll have a look over it. I'll post up the final script when I have it done.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Nice one. That script was basically exactly what I wanted. I altered it slightly to this:
    #!/bin/bash
    
    NUMCPU="$(grep ^processor /proc/cpuinfo | wc -l)"
         
    until [ -z "$1" ]
    do
    	while [ `jobs -p | wc -l` -ge $NUMCPU ] ; do
    		sleep 0.1
        done
      	oggenc -q8 "$1" &
    	shift
    done
    

    Invocation would be: <scriptname> *.flac


  • Moderators, Technology & Internet Moderators Posts: 1,336 Mod ✭✭✭✭croo


    yeah that stuff you removed was just to let you know what was happening. If you have a lot of files it can take a long time and this was just to offer comfort that something was happening.


Advertisement