Skip to content

Tag Archives: bash

Limit number of instances of a specific process and user

22-Jul-10

I’m using this to limit the number of processes that Ampache spawns. Sometimes, it goes hay-wire. [cc_bash] #!/bin/sh cmd=”$1″ lim=”$2″ user=”$3″ || “www” numprocs=ps -U www | grep “$cmd” | wc -l echo “Found $numprocs comparing to $lim” if [ “$numprocs” -gt “$lim” ]; then echo “found $numprocs processes” killall aacplusenc fi [/cc_bash] Be the […]

Using Linux command lockfile in bash scripts

14-Jul-10

I needed to create a script that runs a regression test. I intended to schedule this with a cron job. However, I found that sometimes, my cron jobs would collide with each other. So, I looked to Linux’ command to create a file lock as a semaphore. Here’s the incantation: [cc_bash] # if we’re already […]