AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  AIX lpstat

    Posted Mon July 21, 2014 12:22 PM

    Originally posted by: John2006


    Hi Brother,

    I would like to ensure the print queue is "0" before dayend, how can I create script to check it? exp using lpstat ...etc. May I have sample? I try to write the sample but hard to search the number of job in lpstat.

    Thanks

     


    #AIX-Forum


  • 2.  Re: AIX lpstat

    Posted Wed July 23, 2014 04:05 PM

    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