[HPADM] Summary - Script for Printers.

From: brian irvin (brian944us_at_yahoo.com)
Date: 03/31/05

  • Next message: brian irvin: "[HPADM] Script -ksh"
    Date: Thu, 31 Mar 2005 11:59:03 -0800 (PST)
    To: hpux-admin@dutchworks.nl
    
    

    Thanks to Bill Hassell, Breet geer and Richard wright
    all who gave very useful tips.

    Question:I need to write a script, which captures all
    the print
    jobs older than 7 days and send a mail alert to the
    admin.

    Answers:

    Bill:
    Since a the print jobs are in the same directory
    structure,
    just use find -mtime +7 to locate the jobs. Something
    like
    this:

    find /var/spool/lp/request -name 'dA*' -type f -mtime
    +7
     
    The result from this search wil return all files that
    have
    not been printed in the last 7 days. To mail the
    results
    there are files located:

    #!/usr/bin/sh
    set -u
    export PATH=/usr/bin
    MYFILES=$(find /var/spool/lp/request -name 'dA*' -type
    f -mtime +7)
    [ -n "$MYFILE" ] && echo "$MYFILE" \
       | mailx -s "Spool files > 7 days old"
    sysadmin@yourcompany.com

    Just store the above in a file, add it to cron and run
    it once
    a day, perhaps early in the morning.

    --
    Bill Hassell
    -------------------------------------------------------
    Here is a script that does almost exactly what you
    want. 
    It will warm about print jobs over one day old and
    delete print jobs over a week old. 
    ========================================= 
    #!/bin/sh 
    # * lpdelete - Remove old files from spool queue and
    notify * # 
    # * USAGE: lpdelete.sh 
    # 
    # This script will run "lpstat" command and look at
    all entries. 
    # An email will be sent to "LP_mail" with a warning
    for every file 
    # over one day old. For every file over 7 days old,
    the print job 
    # will be canceled. These will be listed in the
    message as well. 
    # 
    # * END 
    PR=$(basename $0) 
    tmp=/tmp/${PR}.$$ 
    # 
    # to see who "LP_mail" is, look at /etc/mail/aliases
    and view the "include file" 
    # 
    TOADDR=LP_mail 
    # if ctrl-c then remove the tmp file 
    trap 'INTERPT' SIGINT 
    INTERPT () 
    { 
            rm $tmp 
            exit 
    } 
    HOST=$(hostname) 
    ERROR=0 
    # 
    # set DDCHK1 ... DDCHKn to days that are to be skipped
    # in the format of MMM DD 
    # 
    DD=$(date "+%d") 
    MM=$(date "+%m") 
    YY=$(date "+%Y") 
    DD=$(echo $DD | sed 's/^0//') 
    Mon=$(date "+%b") 
    DDCHK1="$Mon $DD " 
    # Function routine to calculate the previous day 
    previous_day () 
    { 
            ((DD = $DD - 1)) 
            if [ $DD -eq 0 ];then 
                    ((MM = $MM - 1)) 
                    if [ $MM -eq 0 ];then 
                            ((YY = $YY - 1)) 
                            MM=12 
                    fi 
                    DD=$(cal $MM $YY | tail -n2 | head -n1
    | awk '{print $NF}') 
                    Mon=$(cal $MM $YY | head -n1 | awk
    '{print $1}' | cut -c1-3) 
            fi 
    } 
    previous_day 
    DDCHK2="$Mon $DD " 
    previous_day 
    DDCHK3="$Mon $DD " 
    previous_day 
    DDCHK4="$Mon $DD " 
    previous_day 
    DDCHK5="$Mon $DD " 
    previous_day 
    DDCHK6="$Mon $DD " 
    previous_day 
    DDCHK7="$Mon $DD " 
    lpstat -o -i | \ 
    # 
    # Following edits will Join two line entry to one line
    # then eliminate any "on ..." and "copies" text. 
    # Then awk is used to extract the desired fields 
    # 
    sed -n '/^[a-z,A-Z,0-9].*/{ 
    N 
    s/\n/ / 
    p 
    }' | \ 
    sed -e 's/ on [^ ]*//' -e 's/[0-9 ]* copies//' | \ 
    awk '{print $1, $2, $5, $6, $7, $9}' \ 
    > ${tmp} 
    # 
    # If the queue is empty, then put something in for 
    # email message to show. 
    # 
    if [ $(cat ${tmp} | wc -l) -eq 0 ];then 
            echo '-none-' > ${tmp} 
    fi 
    sendmail $TOADDR << __EOF__ 
    Subject: print failure report for $HOST 
    SendTo: $TOADDR 
    DisplayFrom: "$HOST $PR results" 
    The following print jobs are more than one day old. 
    The printer may require attention for supplies or
    jams. 
    $(grep -v "$DDCHK1" ${tmp}) 
    The following print jobs are more than seven days old
    and have been deleted. 
    $(grep -E -v
    "($DDCHK1|$DDCHK2|$DDCHK3|$DDCHK4|$DDCHK5|$DDCHK6|$DDCHK7)"
    ${tmp}) 
    The following printers are disabled 
    $(lpstat -p | grep disabled) 
    __EOF__ 
    while read JB TO MM DD TI SZ 
    do 
    /usr/bin/cancel $JB 
    done << __EOF2__ 
    $(grep -E -v
    "($DDCHK1|$DDCHK2|$DDCHK3|$DDCHK4|$DDCHK5|$DDCHK6|$DDCHK7)"
    ${tmp}) 
    __EOF2__ 
    rm ${tmp} 
    exit 
    ==================================================== 
    Richard Wright 
    Thanks
    Brian.
    		
    __________________________________ 
    Do you Yahoo!? 
    Yahoo! Personals - Better first dates. More second dates. 
    http://personals.yahoo.com
    --
                 ---> Please post QUESTIONS and SUMMARIES only!! <---
            To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
           Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
     
     Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
                http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)
    

  • Next message: brian irvin: "[HPADM] Script -ksh"

    Relevant Pages

    • Re: Netcat question
      ... Also, I apologize since I think you might have provided this already, but can we see the virtual device script? ... Maybe a quick & dirty hack fix is to have the virtual device script always append something unobtrusive to the collected print data for no other reason than to garuntee that the print jobs are always at least a few bytes. ... It uses a cheap-o single port print server that snaps onto the centronics plug just like that netgear ps101. ...
      (comp.unix.sco.misc)
    • Re: Netcat question
      ... If you write the virtual device script to simply throw out all output from ... than to garuntee that the print jobs are always at least a few bytes. ... It uses a cheap-o single port print server that snaps onto the centronics ...
      (comp.unix.sco.misc)
    • Re: Biztalk 2006 with SQL-Express - Gert
      ... This is the link for the list of BizTalk 2006 Maintenance Jobs ... Below I provide the details of the execution script with the interval. ... Interval: 1 Minute / Recurring ...
      (microsoft.public.biztalk.general)
    • Re: Plattform independent queuing of computations
      ... The idea ist to put the computation jobs into a database which is read ... The external task uses the database as a queue ... website the socket will be closed when the script is finished and the ... And if the rest of the code doesn't have problems with loops, you can set the execution time longer and memory larger. ...
      (comp.lang.php)
    • Re: prevent users from running system statistic tools
      ... > routines to see how their jobs were running. ... > I considered a script that would issue a talk command to the user. ... Have your manager have a chat with their ...
      (comp.unix.solaris)