Skip to content

Instantly share code, notes, and snippets.

@jamespfinn
Last active November 9, 2016 16:03
Show Gist options
  • Save jamespfinn/5766ba4946453fdb10a1ceef29c6b7c2 to your computer and use it in GitHub Desktop.
Save jamespfinn/5766ba4946453fdb10a1ceef29c6b7c2 to your computer and use it in GitHub Desktop.
This wrapper script will fork castnow. It accepts all castnow options and forks the process to the background.
#!/bin/bash
# 2016.10.08 - jamespfinn@gmail.com
# https://github.com/jamespfinn
#
# This script will fork an instance of castnow (https://github.com/xat/castnow).
# All options passed to this script will be passed to castnow
# e.g.:
# $ ./castnow-fork.sh file1.mp3 file2.mp3 --address 192.168.1.44
#
# This script has only been tested on Linux
# To make it work on OSX the output from 'ps' needs to be handled differently.
# See https://github.com/xat/castnow/issues/169#issuecomment-259262796 for the
# necessary modifications.
#
OUT1=/tmp/castnow-fork.out
OUT2=/dev/null
set -m
{
{ castnow $@ &>$OUT1 ; } &
export pid=$!
(
while kill -0 $pid ; do
if [ "$(ps -o stat -p $pid | tail -1 | cut -c1)" == "S" ]; then
{
echo killing $pid...
kill $pid
}
fi
done
)
} &> $OUT2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment