Hi there all..
I need some help with a script I have.
It's a printing script but what will happen if the printer stays on disabled?
Will it continue in the loop?
How can I change the script so it will only loop like 5 times and if still not working than it send a e-mail with what printer has what problem?
Thanx a million people!
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
}
######################################################
############### 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
;;
*) # Anything else is unsupported.
echo "\nERROR: Unsupported Operating System: $(uname)\n"
echo "\n\t\t...EXITING...\n"
;;
esac
# End of Script
HI Guys
Want help in writing a Script for check and enable the printer if any any is disable in HP-UX automatic after every half hour...
Thanks...:wall: (4 Replies)
Hello,
I need to chack if the printer is out of paper, and send message to operator.
I need to do this from perl script.
The printer have mechanism to check if it have paper. However, the cups does not report "printer out of paper" when I remove the paper, and try to print.
Is there any... (1 Reply)
Good afternoon. :)
I'm rather new to bash scripting, and have probably bitten off a bit more than I can chew to be honest, but I work in a service desk-like environment where one of the main complaints is that it takes our staff a long time to set up network printers on our clients' servers.... (3 Replies)
Good day UNIX forum, could you help me with my clear printer queue script, i have problems with the consistency of this function, sometimes it works sometimes it doesn't. Thanks in advance
}
preRemovePrintQ(){
clear;
echo;
echo... (1 Reply)
Hi,
Is it possible to find the printer location and printer type (whether it is local or network) using command in Linux ?
Thanks in advance. (1 Reply)
Hi,
We check the printer status at the command line by giving the following command and the system gives an output;
lpstat -prn001_hp4000n
When I give the same command in a UNIX script the system gives an error while running the script as "lpstat: not found".
Please let me know... (8 Replies)
Hello
Let me first give a small overview of the setup. All printers are connected to Windows 2000 servers. There are a lot of UNIX (AIX & HP-UX) servers as well which have SAP running.
I'm working on a script to add printers to a specified SAP instance. I want to verify the user input (to... (0 Replies)
We were printing to a serial laser printer with all the HP codes to generate a form (i.e. lines, boxes, etc.) Thus the file is filled w/ control codes. We are switching to an IP printer and we can no longer print directly to the device (i.e. cp text /dev/tty11). It looks like we have to use the lp... (2 Replies)