Reputation: 1175
Really wasn't sure whether to post this in on the Unix SE or here but here goes:
I was trying to get fancy with the asciiquarium
package (https://github.com/cmatsuoka/asciiquarium), trying to make it function like an actual screensaver based on idle time but I seem to have a problem once I send asciiquarium's stdout to /pts/2
(I think the script is calling multiple background tasks). I feel like I should be somehow storing the PID of the asciiquarium background task and then manually killing the task around activated=false
. However, when I do that I end up with a seemingly circular logic in that sending asciiquarium stdout to pts/2
thereby makes the tty no longer idle (right?).
Anyway, how can I send the asciiquarium stdout to /dev/pts/2
and terminate it when user input is detected on dev/pts/2
?
# pts=$(who am i | awk '{print $2}')
pts="pts/2"
echo $pts >> test.log
old=$(stat -c %Y /dev/$pts)
ct=0
activated=false
while true
do
sleep 1s
new=$(stat -c %Y /dev/$pts)
if [[ $new -eq $old ]] # If new and old ts are the same it means that pts is idle
then
((ct++))
echo "$ct" >> test.log
else
ct=0
echo "Resetting count!" >> test.log
activated=false
fi
if [[ $ct -gt 10 ]]
then
if ! $activated
then
activated=true
echo "Activating!" >> test.log
asciiquarium > /dev/$pts &
else
continue
fi
fi
old=$new
done
Upvotes: 0
Views: 44