Lpstat


 
Thread Tools Search this Thread
Operating Systems HP-UX Lpstat
# 8  
Old 09-10-2008
Yes great !
I wrote a script also because queues were always falling in AIX and got fed up having users calling:
I kill the thing in the evening and start the chk_enable by cron with the most troublesome printers in the morning before I work (and so can stay in bed a little bit longer...)
Code:
# chk_enable  printer
PRNT=$1

while true
do
 ISIT=$(lpstat -v$PRNT|head -3|grep READY)
 if [ "$ISIT" = ""  ]
 then
    echo $PRNT " IS KO!!!"
    enable $PRNT
    sleep 10
    lpstat -v$PRNT
 else
    sleep 30
    echo OK
 fi
done


Last edited by vbe; 09-10-2008 at 09:17 AM.. Reason: added code tag...
# 9  
Old 09-10-2008
e.g. yesterday I didnt use my scripts. result:
elo6: /home/vbe# lpstat -W
Queue Dev Status Job Files User PP % Blks Cp Rnk
-------------------- -------------- --------- ------ ------------------ ---------- ---- --- ----- --- ---
SC-0-1-HP4M @160 READY
SC-0-1-HP4M: JetDirect lpd: no jobs queued on the port Auto
SC-0-2-LJ4000N @160 READY

: (WARNING) 0781-375 Connection to server failed.
rembak: errno = 4: A system call received an interrupt.
SC-0-2-LJ4000N SC-0-2-LJ4000N HOST_DOWN
SC-0-3-LJ1100 @160 READY

: (WARNING) 0781-375 Connection to server failed.
rembak: errno = 4: A system call received an interrupt.
SC-0-3-LJ1100 SC-0-3-LJ1100 HOST_DOWN
SC-1-1-LJ4050 @160 READY

: (WARNING) 0781-375 Connection to server failed.
rembak: errno = 4: A system call received an interrupt.
SC-1-1-LJ4050 SC-1-1-LJ4050 HOST_DOWN
SC-1-2-HP4 @160 READY
SC-1-2-HP4: JetDirect lpd: no jobs queued on the port Raw
SC-2-1-LJ4100 @160 READY

: (WARNING) 0781-375 Connection to server failed.
rembak: errno = 4: A system call received an interrupt.
SC-2-1-LJ4100 SC-2-1-LJ4100 HOST_DOWN
SC-2-2-HP4 @160 READY
SC-2-2-HP4: JetDirect lpd: no jobs queued on the port Raw
SC-3-HP4M @160 READY

: (WARNING) 0781-375 Connection to server failed.
rembak: errno = 4: A system call received an interrupt.
SC-3-HP4M SC-3-HP4M HOST_DOWN
lpvbe @160 READY
lpvbe: JetDirect lpd: no entries

NOW:

elo6: /home/vbe# lpstat -W
Queue Dev Status Job Files User PP % Blks Cp Rnk
-------------------- -------------- --------- ------ ------------------ ---------- ---- --- ----- --- ---
SC-0-1-HP4M @160 READY
SC-0-1-HP4M: JetDirect lpd: no jobs queued on the port Auto
SC-0-2-LJ4000N @160 READY
SC-0-2-LJ4000N: JetDirect lpd: no jobs queued on this port
SC-0-3-LJ1100 @160 READY
SC-0-3-LJ1100: JetDirect lpd: no jobs queued on the port Auto
SC-1-1-LJ4050 @160 READY
SC-1-1-LJ4050: JetDirect lpd: no jobs queued on this port
SC-1-2-HP4 @160 READY
SC-1-2-HP4: JetDirect lpd: no jobs queued on the port Raw
SC-2-1-LJ4100 @160 READY
SC-2-1-LJ4100: JetDirect lpd: no jobs queued on this port
SC-2-2-HP4 @160 READY
SC-2-2-HP4: JetDirect lpd: no jobs queued on the port Raw
SC-3-HP4M @160 READY
SC-3-HP4M: JetDirect lpd: no jobs queued on the port Raw
lpvbe @160 READY
lpvbe: JetDirect lpd: no entries
# 10  
Old 09-10-2008
Hmm that would be a good idea.
But I cant use it. Smilie
I work in a hospital.
So it needs to stay running 24/7.
# 11  
Old 09-10-2008
I put this together a few days ago.
Still dint put it in to use yet.
Because I dont know if the loop wil work out well that I put in the script.

I made this cross platform because we also have some linux systems and some solaris servers and so on..
And you'll never know where your gonna need someting like this.

But the service desk script I made for AIX I will still post after I changed it to english.


Code:
##########################################################
############### DEFINE FUNCTIONS HERE ####################
##########################################################
function AIX_classic_printing
{
for Q in $( enq -AW | tail +3 | grep DOWN | awk '{print $1}')
do
     enable $Q
     (( $? == 0 )) || echo "\n$Q print queue FAILED to enable.\n"
done
}

##########################################################

function AIX_SYSV_printing
{
LOOP=0     # Loop Counter - To grab three lines at a time

lpc status all | egrep ':|printing|queueing' | while read LINE
do
     # Load three unique lines at a time
     case $LINE in
     *:) Q=$(echo $LINE | cut -d ':' -f1)
         ;;
     printing*)
         PSTATUS=$(echo $LINE | awk '{print $3}')
         ;;
     queueing*)
         QSTATUS=$(echo $LINE | awk '{print $3}')
         ;;
     esac 

     # Increment the LOOP counter
     (( LOOP = LOOP + 1 ))
     if ((LOOP == 3))  # Do we have all three lines of data?
     then
          # Check printing status
          case $PSTATUS in
          disabled) lpc start $Q >/dev/null
                    (($? == 0)) && echo "\n$Q printing re-started\n"
                    ;;
          enabled|*) :  # No-Op - Do Nothing
                    ;;
          esac

          # Check queuing status
          case $QSTATUS in 
          disabled) lpc enable $Q >/dev/null 
                    (($? == 0)) && echo "\n$Q queueing re-enabled\n"
                    ;;
          enabled|*) :  # No-Op - Do Nothing
                    ;;
          esac
          LOOP=0  # Reset the loop counter to zero
    fi 
done
}

##########################################################

function CUPS_printing
{
LOOP=0 # Loop Counter - To grab three lines at a time

lpc status all | egrep .:|printing|queuing. | while read LINE
do
    # Load three unique lines at a time
    case $LINE in
    *:) Q=$(echo $LINE | cut -d .:. -f1)
        ;;
    printing*)
        PSTATUS=$(echo $LINE | awk .{print $3}.)
        ;;
    queuing*)
        QSTATUS=$(echo $LINE | awk .{print $3}.)
        ;;
    esac

    # Increment the LOOP counter
    (( LOOP = LOOP + 1 ))
    if ((LOOP == 3)) # Do we have all three lines of data?
    then
        # Check printing status
        case $PSTATUS in
        disabled) cupsenable $Q >/dev/null
                  (($? == 0)) && echo -e "\n$Q printing re-started\n"
                  sleep 1
                  ;;
        enabled|*) : # No-Op - Do Nothing
                  ;;
        esac

        # Check queuing status
        case $QSTATUS in
        disabled) accept $Q # >/dev/null
                  (($? == 0)) && echo -e "\n$Q queueing re-enabled\n"
                  ;;
        enabled|*) : # No-Op - Do Nothing
                  ;;
        esac

        LOOP=0 # Reset the loop counter to zero
    fi
done
}

#######################################################

function HP_UX_printing
{
lpstat | grep Warning: | while read LINE
do
      if (echo $LINE | grep 'is down') > /dev/null
      then
           enable $(echo $LINE | awk '{print $3}')
      fi

      if (echo $LINE | grep 'queue is turned off') >/dev/null
      then
           accept $(echo $LINE | awk '{print $3}')
      fi
done
}

################################################################33

function Linux_printing
{
lpc status | tail +2 | while read pqstat[1] pqstat[2] pqstat[3] junk
do
     # First check the status of printing for each printer
     case ${pqstat[2]} in
     disabled)
               # Printing is disable - print status and restart printing
               echo "${pqstat[1]} Printing is ${pqstat[2]}"
               lpc start ${pqstat[1]} 
               (($? == 0)) && echo "${pqstat[1]} Printing Restarted"
             ;;
     enabled|*) : # No-Op - Do Nothing
             ;;
     esac
     # Next check the status of queueing for each printer
     case ${pqstat[3]} in
     disabled) 
               echo "${pqstat[1]} Queueing is ${pqstat[3]}"
               lpc enable ${pqstat[1]}
               (($? == 0)) && echo "${pqstat[1]} Printing Restarted"
              ;;
     enabled|*) :   # No-Op - Do Nothing
             ;;
     esac
done
}

###############################################################

function OpenBSD_printing
{
LOOP=0 # Loop Counter - To grab three lines at a time

lpc status all | egrep ':|printing|queuing' | while read LINE
do
    # Load three unique lines at a time
    case $LINE in
    *:) Q=$(echo $LINE | cut -d ':' -f1)
        ;;
    printing*)
        PSTATUS=$(echo $LINE | awk '{print $3}')
        ;;
    queuing*)
        QSTATUS=$(echo $LINE | awk '{print $3}')
        ;;
    esac

    # Increment the LOOP counter
    (( LOOP = LOOP + 1 ))
    if ((LOOP == 3)) # Do we have all three lines of data?
    then
        # Check queuing status
        case $QSTATUS in
        disabled) lpc enable $Q >/dev/null
                  (($? == 0)) && echo "\n$Q queueing re-enabled\n"
                  sleep 1
                  ;;
        enabled|*) : # No-Op - Do Nothing
                  ;;
        esac

        # Check printing status
        case $PSTATUS in
        disabled) lpc up $Q >/dev/null
                  (($? == 0)) && echo "\n$Q printing re-started\n"
                  ;;
        enabled|*) : # No-Op - Do Nothing
                  ;;
        esac
        LOOP=0 # Reset the loop counter to zero
    fi
done
}

#######################################################

function Solaris_printing
{
LOOP=0     # Loop Counter - To grab three lines at a time

lpc status all | egrep ':|printing|queueing' | while read LINE
do
     # Load three unique lines at a time
     case $LINE in
     *:) Q=$(echo $LINE | cut -d ':' -f1)
         ;;
     printing*)
         PSTATUS=$(echo $LINE | awk '{print $3}')
         ;;
     queueing*)
         QSTATUS=$(echo $LINE | awk '{print $3}')
         ;;
     esac 

     # Increment the LOOP counter
     (( LOOP = LOOP + 1 ))
     if ((LOOP == 3))  # Do we have all three lines of data?
     then
          # Check printing status
          case $PSTATUS in
          disabled) lpc start $Q >/dev/null
                    (($? == 0)) && echo "\n$Q printing re-started\n"
                    ;;
          enabled|*) :  # No-Op - Do Nothing
                    ;;
          esac

          # Check queuing status
          case $QSTATUS in 
          disabled) lpc enable $Q >/dev/null 
                    (($? == 0)) && echo "\n$Q queueing re-enabled\n"
                    ;;
          enabled|*) :  # No-Op - Do Nothing
                    ;;
          esac
          LOOP=0  # Reset the loop counter to zero
    fi 
done
}

######################################################
############### BEGINNING OF MAIN ####################
######################################################

# Is CUPS Running? If CUPS is running we can just
# run the CUPS standard commands.

ps auxw | grep -q [c]upsd
if (( $? == 0 ))
then
    CUPS_printing
    exit $?
fi

# What OS are we running?

# To start with we need to know the UNIX flavor.
# This case statement runs the uname command to
# determine the OS name. Different functions are
# used for each OS to restart printing and queuing.

case $(uname) in

AIX) # AIX okay...Which printer subsystem?
     # Starting with AIX 5L we support System V printing also!
     
     # Check for an active qdaemon using the SRC lssrc command

     if (ps -ef | grep '/usr/sbin/qdaemon' | grep -v grep) >/dev/null 2>&1
     then
           # Standard AIX printer subsystem found
           AIX_PSS=CLASSIC
     elif (ps -ef | grep '/usr/lib/lp/lpsched' | grep -v grep)
     then
           # AIX System V printer service is running
           AIX_PSS=SYSTEMV
     fi

     # Call the correct function for Classic AIX or SysV printing
     case $AIX_PSS in
     CLASSIC)  # Call the classic AIX printing function
               AIX_classic_printing
              ;;
     SYSTEMV)  # Call the AIX SysV printing function
               AIX_SYSV_printing
              ;;
     esac 

      ;;
HP-UX)  # Call the HP-UX printing function
        HP_UX_printing

      ;;
Linux)  # Call the Linux printing function
        Linux_printing
      ;;
OpenBSD) # Call the OpenBSD printing function
        OpenBSD_printing
      ;;
SunOS)  # Call the Soloris printing function
        Solaris_printing

      ;;
*)      # Anything else is unsupported.
 	echo "\nERROR: Unsupported Operating System: $(uname)\n"
        echo "\n\t\t...EXITING...\n"
      ;;
esac

# End of Script

# 12  
Old 09-10-2008
Dont kill the process then...
It may be fine tuned for your needs... I work in local administration and cant always go and travel to sites to see what users are about...
One issue I see regularly is when someone switch off a printer (you know the blon secretary type...) when not supposed to... things go wrong short after, So there is a correlation between time spent by the AIX spooler trying to communicate with the printer "down" and timeout leading to other printers to queue and then???
I just cant get hold of what is going on, and this never happens with HP....
# 13  
Old 09-10-2008
I cant help you much in your script here for I dont have any trouble under HP and so dont know what to expect as message...
But in your script it will not work for in HP_UX_printing
just lpstat wont return you anything... you should use something like
lpstat -t #(| grep printer?)
Mind you I can give it a try and test on HP and on AIX (I dont know if we have solaris with printers...)


New
I just checked and saw that I dont see nothing on HP because no issue:
ant:/home/vbe/scripts/lp $ lpstat
ant:/home/vbe/scripts/lp $
ant:/sm/export/hpux/11.11 $ lpstat -t |grep printer
printer LJ_3b1 is idle. enabled since Jul 29 16:38
printer lp3 is idle. enabled since Jul 29 16:38
printer lp8 is idle. enabled since Jun 18 18:55
printer lp9 is idle. enabled since Jul 29 16:38
printer lpvbe disabled since Sep 9 16:23 -
printer lp0 is idle. enabled since Jul 29 17:06
printer lpdgas is idle. enabled since Oct 21 15:33
printer lpjuan is idle. enabled since Apr 27 11:05
printer LJcolor is idle. enabled since Dec 1 14:03
printer scarpatest is idle. enabled since May 31 16:15

Now if I configure a printer I know doesnt exist on another box:

mos:/home/vbe $ ping xerox1
PING xerox1: 64 byte packets

----xerox1 PING Statistics----
21 packets transmitted, 0 packets received, 100% packet loss
mos:/home/vbe $ sam&
[1] 3317
mos:/home/vbe $ lpstat
no entries
mos:/home/vbe $ timex lpstat
no entries
connection to xerox1 is down
mos: Warning: xerox1 queue is turned off
mos: Warning: xerox1 is down

connection to xerox2 is down

mos: xerox2: ready and waiting

printer queue for xerox3
Printer status : Idle.(Ready.)
Online/Offline : Online.


no entries.



real 2:30.06
user 0.03
sys 0.10

mos:/home/vbe $

So my concern here about your script is the delay for the lpstat output...


vs lpstat -p:
fence priority : 0
printer B250_LJ4050 is idle. enabled since Dec 14 12:58
fence priority : 0
printer lpvbe is idle. enabled since Dec 14 12:58
fence priority : 0
printer xerox1 disabled since Dec 14 13:00 -
reason unknown
fence priority : 0
printer xerox2 is idle. enabled since Dec 14 12:58
fence priority : 0
printer xerox3 is idle. enabled since Dec 14 12:58
fence priority : 0
printer B246_LJ4000N is idle. enabled since Jun 27 10:53
fence priority : 0

real 0.12
user 0.01
sys 0.01

Last edited by vbe; 09-10-2008 at 11:59 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Lpstat output in mb?

Hi all, Newbie to the site here and fairly novice to UNIX\LINUX so please bear with me.:) My question is; can the lpstat -t command show the size of the print jobs in mb or gb instead of bytes? They would be much easier to view this way. For more information of what I'm on about; please... (1 Reply)
Discussion started by: Melikins
1 Replies

2. UNIX for Advanced & Expert Users

lpstat ?

Hi, can somebody tell me what is the difference between `lpstat -s` and `lpstat -v` command. thanks. (3 Replies)
Discussion started by: anandgodse
3 Replies

3. Solaris

Need help with lpstat command

Hi lpstat reports me "Failed to contact service for xxxxxx: not-found" lpstat -p test -l printer test unknown state. enabled since Oct 27 12:01 2009. available. Remote Name: XXXXXX Remote Server: sunsrv Failed to contact service for xxxxxx: not-found can someone help... (1 Reply)
Discussion started by: xtreams
1 Replies

4. AIX

lpstat issues

Hi, I tried to migrate a server, I installed AIX on a new server and I want to configure the printer queues. I copied all of files from the old server where the printer queues are working fine. I followed these steps: 1. copy the /etc/qconfig (make a copy of the original before) 2. Copy the... (10 Replies)
Discussion started by: imad77
10 Replies

5. Shell Programming and Scripting

lpstat

Hi, here is lpstat command with queue name. queue name is not valid but lpstat takes my local queue and shows the following results.is there any way that i can stop it after waring message and dont take local print queue. i would like to print a message that queue is not valid but when lpstat... (4 Replies)
Discussion started by: sagii
4 Replies

6. Shell Programming and Scripting

lpstat throughs warning

Hi Guys, I am geting this message ".status: (WARNING): 0781-102 Invalid printer name: xerox".i m reading printer name from a text file.i try to print the value reading from file is correct xerox. if run lpstat -pxerox -l it works fine but when i try to read from file it throughs warining.please... (1 Reply)
Discussion started by: sagii
1 Replies

7. Shell Programming and Scripting

How to compare result lpstat with hostsfile

Hi there all, I got a long list of printers installed and a longer list of printers in my hosts file. In the hosts file I got a even longer list of printers in the hosts file I got the IP adress of all printers next to the printer name. How can I get a script working to get the printers... (0 Replies)
Discussion started by: draco
0 Replies

8. SCO

non root user can't use lpstat

I don't know if anyone still looks at this forum or not, but here goes. I've got two identical SCO OpenServer 5.0.7 machines, fully patched and updated. On one the non-root user can do lpstat -p and it will display a list of printers and their status, on the other: $ lpstat -p UX:lpstat: ERROR:... (3 Replies)
Discussion started by: checkpro
3 Replies

9. UNIX for Advanced & Expert Users

lpstat

Hi, I have been using Hp so far and I am a new user to Solaris.. well, in HP Unix, if I type 'lpstat' if gives me the list of printers connected to the network and their status.. but in solaris it only gives the details if there is any job on the queue. I just want to know what is the... (3 Replies)
Discussion started by: sskb
3 Replies

10. UNIX for Dummies Questions & Answers

lpstat -t

When you do a lpstat -t it displays all your printers and tty values. Where is the file that stores this information in SCO 5.0.5? Thanks in advance Stufine (2 Replies)
Discussion started by: stufine
2 Replies
Login or Register to Ask a Question