kantor
September 28th, 2008, 12:43 PM
I write this scrips to automately check the ink's levels of my printer. I would the script to work that way:
0) sleep until the printer is on
1) tell a warning about the ink that reach less than 5% level at the last check
2) read the new levels
3) put the level in a notification on the taskbar
4) recheck the levels after a time of sleep or go to sleep at point 0 when printer goes off
The thing is, i put a lots of commands in a endless loop... but when zenity --notification is running there's no way to continue the loop. I mean with or without the --listen option.
This is the code:
#!/bin/bash
while true; do
while [ ! -e /dev/usb/lp0 ]; do
# Sleep until the printer device file is created
sleep 1
done
sleep 30s
#it tells about the ink's that was at less than 5% level at last check
if espeak -p 90 -v it "`cat warn`"
then
zenity --error --text="/dev/dsp busy problem with telling remind warnings about exausted inkpack checked at the last check"
fi
while [ -e /dev/usb/lp0 ]; do
#it reads the level of the ink's in the printer and if it is lower
#than 5% it change inkstat to make note of the need to change the
#inkpack
escputil -r /dev/usb/lp0 -i>status
inkstat=0000
num=5
#this next commands extract the value of percentage level of Cyan
string=`less status|grep Cyan`
clev=`echo ${string:39}`
if [ $clev -le $num ]
then
let "inkstat += 1"
fi
#this is for yellow
string=`less status|grep Yellow`
ylev=`echo ${string:39}`
if [ $ylev -le $num ]
then
let "inkstat += 10"
fi
#and so on...
string=`less status|grep Magenta`
mlev=`echo ${string:39}`
if [ $mlev -le $num ]
then
let "inkstat += 100"
fi
string=`less status|grep Black`
blev=`echo ${string:39}`
if [ $blev -le $num ]
then
let "inkstat += 1000"
fi
echo $inkstat>levs
echo Cyan $clev%>>levs
echo Yellow $ylev%>>levs
echo Magenta $mlev%>>levs
echo Black $blev%>>levs
#now the inkstat variable contains all the informations about the
#levels of inks in the printer
#and these commands write a warning about the inkpacks that needs to
#be changed
case "$inkstat" in
1111)
echo "Change all">warn
;;
1110)
echo "Change Black, Magenta and Yellow">warn
;;
1101)
echo "Change Black, Magenta and Cyan">warn
;;
1011)
echo "Change Black, Yellow and Cyan">warn
;;
111)
echo "Change Magenta, Yellow and Cyan">warn
;;
1100)
echo "Change Black and Magenta">warn
;;
1010)
echo "Change Black and Yellow">warn
;;
1001)
echo "Change Black and Cyan">warn
;;
110)
echo "Change Magenta and Yellow">warn
;;
101)
echo "Change Magenta and Cyan">warn
;;
11)
echo "Change Yellow and Cyan">warn
;;
1000)
echo "Change Black">warn
;;
100)
echo "Change Magenta">warn
;;
10)
echo "Change Yellow">warn
;;
1)
echo "Change Cyan">warn
;;
*)
echo "All ok">warn
;;
esac
#this added a warning at the end of levs file
cat warn>>levs
#and here is the problem, this command create a notification and the loop doesn't go on.
zenity --notification --listen --window-icon="info" --text="`cat levs`"
sleep 30m
done
done
0) sleep until the printer is on
1) tell a warning about the ink that reach less than 5% level at the last check
2) read the new levels
3) put the level in a notification on the taskbar
4) recheck the levels after a time of sleep or go to sleep at point 0 when printer goes off
The thing is, i put a lots of commands in a endless loop... but when zenity --notification is running there's no way to continue the loop. I mean with or without the --listen option.
This is the code:
#!/bin/bash
while true; do
while [ ! -e /dev/usb/lp0 ]; do
# Sleep until the printer device file is created
sleep 1
done
sleep 30s
#it tells about the ink's that was at less than 5% level at last check
if espeak -p 90 -v it "`cat warn`"
then
zenity --error --text="/dev/dsp busy problem with telling remind warnings about exausted inkpack checked at the last check"
fi
while [ -e /dev/usb/lp0 ]; do
#it reads the level of the ink's in the printer and if it is lower
#than 5% it change inkstat to make note of the need to change the
#inkpack
escputil -r /dev/usb/lp0 -i>status
inkstat=0000
num=5
#this next commands extract the value of percentage level of Cyan
string=`less status|grep Cyan`
clev=`echo ${string:39}`
if [ $clev -le $num ]
then
let "inkstat += 1"
fi
#this is for yellow
string=`less status|grep Yellow`
ylev=`echo ${string:39}`
if [ $ylev -le $num ]
then
let "inkstat += 10"
fi
#and so on...
string=`less status|grep Magenta`
mlev=`echo ${string:39}`
if [ $mlev -le $num ]
then
let "inkstat += 100"
fi
string=`less status|grep Black`
blev=`echo ${string:39}`
if [ $blev -le $num ]
then
let "inkstat += 1000"
fi
echo $inkstat>levs
echo Cyan $clev%>>levs
echo Yellow $ylev%>>levs
echo Magenta $mlev%>>levs
echo Black $blev%>>levs
#now the inkstat variable contains all the informations about the
#levels of inks in the printer
#and these commands write a warning about the inkpacks that needs to
#be changed
case "$inkstat" in
1111)
echo "Change all">warn
;;
1110)
echo "Change Black, Magenta and Yellow">warn
;;
1101)
echo "Change Black, Magenta and Cyan">warn
;;
1011)
echo "Change Black, Yellow and Cyan">warn
;;
111)
echo "Change Magenta, Yellow and Cyan">warn
;;
1100)
echo "Change Black and Magenta">warn
;;
1010)
echo "Change Black and Yellow">warn
;;
1001)
echo "Change Black and Cyan">warn
;;
110)
echo "Change Magenta and Yellow">warn
;;
101)
echo "Change Magenta and Cyan">warn
;;
11)
echo "Change Yellow and Cyan">warn
;;
1000)
echo "Change Black">warn
;;
100)
echo "Change Magenta">warn
;;
10)
echo "Change Yellow">warn
;;
1)
echo "Change Cyan">warn
;;
*)
echo "All ok">warn
;;
esac
#this added a warning at the end of levs file
cat warn>>levs
#and here is the problem, this command create a notification and the loop doesn't go on.
zenity --notification --listen --window-icon="info" --text="`cat levs`"
sleep 30m
done
done