Originally posted by: GarlandJoseph
You could do this two ways: count the number of files in the spool directory or parse the output of lpstat.
By examples...
On my AIX test system I print to a file in dev directory as my printer/queue. My jobs live in this directory:
/var/spool/lpd/qdir
I submitted a job and held it with enq -H x.x
enq -H x.x
Here it is in the queue...
root@josephgr josephgr] lpstat
Queue Dev Status Job Files User PP % Blks Cp Rnk
------- ----- --------- --- ------------------ ---------- ---- -- ----- --- ---
ascii print READY
HELD 3 x.x root 1 1 1
Parsing lpstat output
The magic is this command....
lpstat | egrep -v "^Queue|^----|^ascii" #I strip the header and the queue name
[root@josephgr josephgr] lpstat | egrep -v "^Queue|^----|^ascii"
HELD 3 x.x root 1 1 1
In a script you could do...
if [[ `lpstat | egrep -v "^Queue|^----|^ascii" | wc -l | tr -d ' '` = 0 ]]
then
"no jobs"
else
echo "I got jobs"
fi
By counting spool directory for files....
The key commands is this...
ls | wc -l | tr -d ' '
Spool...
[root@josephgr josephgr] ls -l /var/spool/lpd/qdir
total 8
-rw-rw---- 1 root printq 1539 Jul 23 14:47 n0root:ascii$#@!tZEb
In a script...
if [[ `ls | wc -l | tr -d ' '` = 0 ]]
then
"no jobs"
else
echo "I got jobs"
fi
#AIX-Forum