By fernando | March 10, 2011

Piping data to multiple processes

Here’s a simple shell script to stream data to multiple processes. It has many applications, but the reason I wrote it is to stream the same data to multiple netcat processes on remote machines. Here’s the code: #!/bin/bash usage() { cat <&2 usage : multi-fifo target0 [target1 [target2 [...]]] Where each targetN is a program [...]

By fernando | January 12, 2009

Running commands from the shell with a timeout (pt 2)

Here’s an improved version of the safecmd script. This one doesn’t always wait for $timeout seconds even if the command you’re running exits successfully. In that case, it kills the monitor script and ends at the proper time. Here’s the code: #!/bin/bash timeout=$1 command=$2 shift 2 check_pid_name() { command=$1 childpid=$2 [ -d /proc/$childpid ] || [...]

By fernando | January 10, 2009

Running commands from the shell with a timeout

Sometimes, in a shell script, you need to run a command that might go on forever (or an amount of time long enough to be called forever) due to poor coding of the software and wrong external conditions (network down or overloaded, overloaded system, a changed private key, etc). In order to avoid this situations, [...]