Coder Social home page Coder Social logo

shellutils's Introduction

shellutils

shellutils is collection of command line utilities that I tossed together as a way to save shell scripts that may be useful so that I don't have to keep rewriting them. I wrote them to be used with bash, but I suspect they make work in ksh or sh too.

job_pool.sh

job_pool.sh is a library that you can source from a shell script so that you can keep n number of jobs running at any one time instead of kicking them off all at the same time and saturating the host. It uses a pre-fork type of model and start a bunch of working to kick off your jobs.

The following is a sample program that uses it.

#!/bin/bash

. job_pool.sh

function foobar()
{
    # do something
    true
}   

# initialize the job pool to allow 3 parallel jobs and echo commands
job_pool_init 3 0

# run jobs
job_pool_run sleep 1
job_pool_run sleep 2
job_pool_run sleep 3
job_pool_run foobar
job_pool_run foobar
job_pool_run /bin/false

# wait until all jobs complete before continuing
job_pool_wait

# more jobs
job_pool_run /bin/false
job_pool_run sleep 1
job_pool_run sleep 2
job_pool_run foobar

# don't forget to shut down the job pool
job_pool_shutdown

# check the $job_pool_nerrors for the number of jobs that exited non-zero
echo "job_pool_nerrors: ${job_pool_nerrors}"

The interface consists of four public functions and one variable that reports how many jobs exited non-zero.

# \brief initializes the job pool
# \param[in] pool_size  number of parallel jobs allowed
# \param[in] echo_command  1 to turn on echo, 0 to turn off
function job_pool_init()

# \brief waits for all queued up jobs to complete and shuts down the job pool
function job_pool_shutdown()

# \brief run a job in the job pool
function job_pool_run()

# \brief waits for all queued up jobs to complete before starting new jobs
# This function actually fakes a wait by telling the workers to exit
# when done with the jobs and then restarting them.
function job_pool_wait()

# \brief variable to check for number of non-zero exits
job_pool_nerrors=0

This was inspired by a discussion on StackOverflow.

genpass.sh

genpass.sh is a random password generator, it will produce a random password of the desired length which is suitable for manual entering via the keyboard.

  • Requires uuencode to be in the search path
  • Usage: genpass.sh <length> (default: 8)

naud.sh

Naud is a bash script for normalizing audio files using the normalize-audio utility. It is specifically aimed at mp3, ogg and flac files.

NAME

naud - adjust levels of flac, mp3 or ogg files by decoding to wav, running them through normalize-audio(1) and then re-encoding.

SYNOPSIS

naud [OPTION1]... [FILE1]... [OPTION2]... [FILE2]...

DESCRIPTION

Adjust levels of flac, mp3 or ogg files by encoding to wav, running them through normalize-audio and then re-encoding. This requires as much extra disk space as the sum of all flac, mp3 or ogg files to be decoded. Unless the encoded file type is different from the input file type the original file will be overwritten.

A file is any parameter not beginning with a "-", for naud a file may also be a directory. An option is any parameter beginning with "-". Options, when set, will affect any later file or directory specified. Any option may be set to a different value later on after which the new value is used for all later files.

OPTIONS

-o TARGET

TARGET is one of "same", "ogg", "vorbis", "mp3", or "flac". "vorbis" is a synonym for "ogg". The default for this option is "same". When set to "same" this option causes naud to re-encode the files using their original encoding type and will overwrite the original file. Any other option forces re-encoding to the type given in the option. This is mainly used for re-encoding flac files into another type such as mp3 or ogg. It may also be useful if you own an old or badly designed audio player which can play only mp3 files although, generally, it is not a good idea to encode mp3 to ogg or vice-versa. There is little point in re-encoding both mp3 and ogg files to flac.

-t DIRECTORY

Because naud can use a lot of temporary space this option allows you to specify the temporary directory to use. Naud will create temporary directories under DIRECTORY for its use. The default for this option is the value of the environmental variable TMP.

Pass-through Options

The following options are passed through to normalize-audio:

  • -a AMP
  • -g ADJ
  • -n
  • -T THR
  • -b
  • -m
  • -v
  • -q

Although -q and -v are likely to be of little use as naud captures all the output of normalize-audio.

Because naud allows options to span multiple files this presents a problem if you want to turn off an option. In this case all the above options which are passed to normalize-audio can be switched off by adding a "-" as a suffix. Thus to switch off "-a 2" you would use "-a-", to switch off -n you would use "-n-", etc. It is permitted to use an option that has a value mulitple times, in this case the value used will change to the latest. Please note that long options for mormalize-audio (e.g. --clipping) are not permitted.

SINGLE MODE

If a single file is specified then naud will normalize that file. File lists are allowed thus "*" will expand to all files in the current directory and naud will treat this as a list of single files. Naud will ignore all non-flac, non-mp3 and non-ogg files.

BATCH MODE

If a directory is specified then naud will batch normalize all audio files in that directory. The difference between this and normalizing a single file is that during batch normalization the volume of the files relative to each other remains unaffected. This is useful when normalizing whole albums. The assumption here is that whole albums will reside in their own unique directory. In practice this is not usually a problem.

TAGS

Naud will preserve the following audio tags:

  • Title
  • Artist
  • Album
  • Track number
  • Year
  • Genre
  • Comments

LOSSY COMPRESSION

For files that use lossy compression (mp3 and ogg) naud will attempt as best it can to re-create the quality of the original file. This is a tricky subject and involves some magical incantations. The natures of mp3 and ogg are such that it is impossible to make an exact re-creation of the original. Naud will do its best to keep the quality of the original file without overdoing it and making files that are over-large. There are a number of heuristics that are used for mp3: for very high bit rate files a constant bit rate encoding will be used, for very low bit rate files then average bit rate encoding will be used, for the more common cases naud will encode mp3 files using a variable bit rate scheme. When encoding lossy files from flac files the defaults used are "-V 0" to lame for mp3 and "-q 6" to oggenc for ogg. These values are set near the top of the naud script and are therefore easily changed, take a look at the lame and oggenc man pages to see what these values mean.

REQUIREMENTS

Naud is a bash script and relies on other programs for normalizing audio files. The dependencies are:

  • normalize-audio
  • sox
  • lame
  • vorbis-tools
  • flac

shellutils's People

Contributors

geoffclements avatar vincetse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shellutils's Issues

feature request : endless process managment

Hi,

Thanks for this code snippet, I try to get the thinking to implement this king of pool process management for endless processes ...
let say that I want 10 simultaneous processes running at the same time ... all the time ... each time on e finish, I launch another one within the limit of 10 simultaneous ...
I would add that
- if one of the process send back a errorcode > 0 then limit to 1 process simultaneous (and maybee add a delay between relaunch)
- depending of the errorcode sentback, change the max number of simultaneous processes

in the sample, I fullfill the queue and then wait for the end of it ... not good enough here ..

Thanks for any help you could provide !!

Stéphane

Minor: Incorrect job_pool_nerrors in the echo off mode

Hi,

I am playing with the sample ./job_pool_sample.sh and have noticed that it dumps job_pool_nerrors: 0 by default when the job pool is created in non-echo mode, even though there are two jobs that fail (return false). In the interactive mode (echo on) it correctly dumps 2 failures.

The problem seems to be in the _job_pool_worker(), where the _job_pool_print_result_log() is used to log the result into the log file and which does nothing for the non-echo mode.

I can provide a pull request with the fix, if helpful (changing to plain echo and adding echo on condition into the _job_pool_print_result_log().

Regards,,

Martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.