Skip to content

Instantly share code, notes, and snippets.

@ah-itagile
Last active November 18, 2016 22:09
Show Gist options
  • Save ah-itagile/64d5ff4c88860f02fdfffeb0d4806f8a to your computer and use it in GitHub Desktop.
Save ah-itagile/64d5ff4c88860f02fdfffeb0d4806f8a to your computer and use it in GitHub Desktop.
#!/bin/bash
oldUsage=0
while true
do
usage=`ps -e -o %cpu | awk '{s+=$1} END {print int(s)}'`
echo " Usage=" $usage
if [ "$usage" -gt 99 ];
then
usage=99
elif [ "$usage" -gt 70 ];
then
usage=50
else
usage=10
fi
echo " outputlevel=" $usage
if [ "$oldUsage" != "$usage" ];
then
pidold=$pid
oldUsage=$usage
afplay rainforest.mp3 -v 0."$usage" &
sleep 1
pid=`echo $!`
if [ ! -z "$pidold" ];
then
echo "killing pid=" $pidold
kill $pidold
fi
fi
sleep 3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment