See here for unformatted version.
PATH=$PATH:$HOME/bin/
export PATH
function run1() {
timesless1hour=`who -u | sed 's!\.!00:00!g' | sort +5 | sed -n 's!.* *00:\(..\) *.*$!\1!p'`
for i in $timesless1hour ; do
if [ $i -le 30 ] ; then
return 0
fi
done
return 1
}
function run2() {
load=`awk '{print $1}' /proc/loadavg`
if `echo "$load" '<' 0.4 | bc` ; then
return 0
fi
return 1
}
if [ -e /var/tmp/background.pid ] ; then
kill `cat /var/tmp/background.pid`
fi
echo $$ > /var/tmp/background.pid
picknewbackground.sh sleep 600
while : ; do
if run1 ; then
if run2 ; then
picknewbackground.sh
fi
sleep 600
else
sleep 3600
fi
done