Skip to content

Instantly share code, notes, and snippets.

@samirfor
Created February 1, 2017 16:51
Show Gist options
  • Save samirfor/a99c7a9bcf692caee2264a8d220ccb46 to your computer and use it in GitHub Desktop.
Save samirfor/a99c7a9bcf692caee2264a8d220ccb46 to your computer and use it in GitHub Desktop.
Bash script to play a song when a process ends.
#!/bin/bash
# Bash script to play a song when a process ends.
# License MIT <https://opensource.org/licenses/MIT>
# Author: @samirfor
PID=$1
SONGFILE=$2
if [ "${PID}x" = "x" ] || [ ! -r "${SONGFILE}" ]; then
echo "usage: $0 <pid> <songfile>" && exit 1
fi
ps --pid $PID &>/dev/null
[ $? -ne 0 ] && echo "PID does not exist." && exit 2
while sleep 1; do ps --pid $PID &>/dev/null; [ $? -eq 0 ] || break; done
mpg123 "$SONGFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment