[HPADM] SUMMARY: script

From: Dinesh Devan (ix24@btc.com.bh)
Date: Sun Aug 11 2002 - 04:17:29 EDT


Many thanks to Bob Vance, Bill Thompson and Anil Rajapure

Following is the response from Bob Vance.

lpstat -s > /tmp/z
To combine the entire lines:
awk '{{x=$0}{while (getline){print x " " $0 ; if (getline){x=$0} } } }'
</tmp/z

To just get the desired fields. Instead of saving and combining the entire
record ($0), just save $3 from the first line and then combine it with $3
and $5 from the second line:
awk '{{x=$3}{while (getline){print x " " $3 " " $5 ; if (getline){x=$3} }
} }' </tmp/z

response from Bill Thompson.

#!/bin/sh

oldIFS="$IFS"

IFS="
"

for LINE in $(lpstat -s | grep -v default); do

    echo $LINE | grep -q 'device for'

    if (( $? == 0 )); then

        PRINTER_NAME=$(echo $LINE | awk '{print $3}')

    else

        REMOTE_PRINTER_NAME=$(echo $LINE | awk '{print $3}')

        DESTINATION=$(echo $LINE | awk '{print $5}')

        ... do something with $PRINTER_NAME, $REMOTE_PRINTER_NAME, &
$DESTINATION ...

    fi

done

Rgds,
Dinesh.

Hi Admins,

     Following is the output of an lpstat -s command.

device for prt1: /dev/null
    remote to: prt1 on x.x.x.x
device for prt2: /dev/null
    remote to: prt2 on y.y.y.y

I would like to join the above output as follows

device for prt1: /dev/null remote to: prt1 on x.x.x.x
device for prt2: /dev/null remote to: prt2 on y.y.y.y

This is needed because i need to extract printer name ($3), remote printer
name($7) and printer destination($9) from the above to use in a script.

Appreciate your help.

Thanks & Rgds,
Dinesh.

***Disclaimer***********************************************
Please note the following points:

* This message and any attachments thereto may contain
  privileged or proprietary information, and are intended
  for the sole use of the addressee(s). Total or partial
  reproduction, communication, distribution or use of this
  information by persons other than the addressee(s) is
  prohibited.
* If you have received this message in error, please notify
  the sender either by telephone or message and delete the
  message from any computer.
* This message and any attachments have been scanned by
  Batelco for malicious code on best efforts basis for your
  protection.

Thank you for your cooperation.
************************************************************

***Disclaimer***********************************************
Please note the following points:

* This message and any attachments thereto may contain
  privileged or proprietary information, and are intended
  for the sole use of the addressee(s). Total or partial
  reproduction, communication, distribution or use of this
  information by persons other than the addressee(s) is
  prohibited.
* If you have received this message in error, please notify
  the sender either by telephone or message and delete the
  message from any computer.
* This message and any attachments have been scanned by
  Batelco for malicious code on best efforts basis for your
  protection.

Thank you for your cooperation.
************************************************************

--
             ---> 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)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:17 EDT