- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Selection option within a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 12:31 PM
09-25-2002 12:31 PM
I have this script here which selects all printers within the /etc/lp/interface directory and performs an hpnpadmin command against each one, then puts the output to screen.
What I am trying to figure out here is how to modify this script so that I can possibly run the script and select an individual printer for querying, in other words allow an input on the screen asking for the printer queue name to lookup.
ex: printstatus mv2itd08
As the current script is written it will select all printers due to the path listed as /etc/lp/interface/*.
Any idea's.
TYIA.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 12:40 PM
09-25-2002 12:40 PM
SolutionYou could use something like
if [ "$1" = "" ]
then
run stuff just for one printer
else
do something else to check every printer
fi
If you want to have the script ask for the printer name you can use
echo "Enter Printer Name:\c"
read printer_name
which will allow the user to enter the printer name and this will place the entered name into the variable $printer_name.
Then use something similar to the above if then else like this
if [ "$printer_name" = "all" ]
then
do something for all printers
else
do something for specific printer
fi
beyond this, I would need to see the script to give more exact suggestions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 12:40 PM
09-25-2002 12:40 PM
Re: Selection option within a script
echo "Please enter the name of the printer wish to query\c"
read printer
printstatus $printer
?
HTH
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 12:42 PM
09-25-2002 12:42 PM
Re: Selection option within a script
Perhaps this may help:
#!/usr/bin/sh
cd /etc/lp/interface || exit 1
if [ $# -eq 0 ]
then
set -- *
fi
for p in $@
do
if [ -x $p ]
then
hpnpadmin $p ...
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 12:44 PM
09-25-2002 12:44 PM
Re: Selection option within a script
I'd probably do something like this:
#!/usr/bin/sh
if [ $# -eq 1 ]
then
echo "do this printer ---> $1"
else
echo "do_all_printers"
fi
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 01:19 PM
09-25-2002 01:19 PM
Re: Selection option within a script
Here it is:
mvitux01@/opt/CHS/root/bin# more printstatus
#! /usr/bin/ksh
# This script is utilized to gather printer information on all print queue's installed
# on a system using the hpnpadmin command.
# Environmental section
set -u
BASEDIR=/opt/CHS/root/bin
DATE=`date +%m/%d/%Y`
YDATE=`TZ=CST+24 date +%m/%d/%Y`
SCRIPT_EXECUTION_TIME=$(date +'%H:%M:%S')
SCRIPT_REVISION="HPUX-b.11.00.01"
SCRIPT_HPUX_VERSION=$(uname -r)
SCRIPT_SYSTEM=$(uname - n)
SCRIPT_USER=$(whoami)
SCRIPT_EXECUTION_TIME=$(date +'%Y/%m/%d/%H:%M:%S')
echo $SCRIPT_SYSTEM \(Version $SCRIPT_REVISION\) $SCRIPT_EXECUTION_TIME
echo _____________________________________________________________________
echo
if [ ${SCRIPT_USER} != "root" ] ; then
echo
echo "This program must be executed utilizing the root logon id only"
echo
return 501
fi
echo _______________________________________________________________________
# Gather information about printer queue's on system.
##################################################################################
cd /etc/lp/interface
for i in $(grep "PERIPH=" /etc/lp/interface/* |grep -v "MODEL")
do
qname=`echo $i | cut -d: -f 1 | cut -d/ -f 5`
ip=`echo $i | cut -d= -f 2`
echo Queue name: $qname
echo Printer name / IP address: $ip
hpnpadmin -iqS $ip
echo ""
echo ""
done
mvitux01@/opt/CHS/root/bin#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 01:41 PM
09-25-2002 01:41 PM
Re: Selection option within a script
Looking at:
cd /etc/lp/interface
for i in $(grep "PERIPH=" /etc/lp/interface/* |grep -v "MODEL")
do
qname=`echo $i | cut -d: -f 1 | cut -d/ -f 5`
ip=`echo $i | cut -d= -f 2`
echo Queue name: $qname
echo Printer name / IP address: $ip
hpnpadmin -iqS $ip
echo ""
echo ""
done
I suggest doing it this way:
cd /etc/lp/interface || exit 1
if [ $# -eq 0 ]
then
set -- *
fi
grep -l '^PERIPH=' $@ | while IFS=':=' read qname junk1 ip junk2
do
cat <<-EOF
Queue name: $qname
Printer name / IP address: $ip
$(hpnpadmin -iqS $ip)
EOF
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 01:42 PM
09-25-2002 01:42 PM
Re: Selection option within a script
Correction, drop the -l from the grep... I was working with two ideas and chose the second. Sorry about that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2002 03:13 PM
09-25-2002 03:13 PM
Re: Selection option within a script
printernames=$(grep "PERIPH=" /etc/lp/interface/* |grep -v "MODEL")
print "Select the number of the printer(s) blah ...\n"
PS3="Enter the number of your selection here ->\c"
invalid='true'
while $invalid = 'true'
do
select i in $printernames "All Printers"
do case $i in
'a printer name')
invalid='false'
hpnpfunction $i
break;;
'All Printers') for j in $printernames
do
invalid='false'
hpnpfunction $j
done
*) print -u2 'You've entered an invalid number.'
esac
done
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 05:14 AM
09-26-2002 05:14 AM
Re: Selection option within a script
I incorrectly typed the wrong function name as "select_printer" instead of "single_printer".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2002 05:44 AM
09-26-2002 05:44 AM
Re: Selection option within a script
#!/usr/bin/sh
let arg=0
cd /etc/lp/interface
if [[ "$1" = "" ]] ; then
list="`ls`"
else
list="$*"
let arg=1
fi
for i in $list
do
if [[ -d $i ]] ; then
continue
fi
/opt/hpnpl/bin/ishpnp $i
if [[ $? -eq 0 ]] ; then
printf "%-10s is a JetDirect printer - " $i
/opt/hpnpl/bin/hpnpadmin -E $i
else
if [[ $arg -eq 1 ]] ; then
printf "ERROR: %10s is NOT a JetDirect printer\n" $i
fi
:
fi
done
exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2002 06:15 AM
09-27-2002 06:15 AM
Re: Selection option within a script
#!/bin/ksh
# Defaults
PS3="Please select desired printer: "
fulllist="`cd /etc/lp/interface;ls`"
all_printers ()
{
return
# This is where your current syntax goes.
# Ex: hpnpadmin ${fulllist} If you can send all devices into the command ?
}
select_printer ()
{
select prtname in ALL Quit ${fulllist}
do
[ "${prtname}" = "Quit" ] && exit 0
if test -n "${prtname}"
then
if test "${prtname}" = "ALL"
then
prtlist="${fulllist}"
else
prtlist="${prtname}"
fi
break
fi
done
# Put the syntax for running the hpnpadmin
# Ex: hpnpadmin ${prtlist}
}
# Main
if test ${#} -ne 0
then
while getopts :s option
do
case ${option} in
s) select_on="Y" ;;
?) echo "Usage: ${0} [<-s>] (-s turns select option on)."
exit 4 ;;
esac
done
fi
[ "${select_on}" = 'N' ] && all_printers || single_printer
exit 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2002 06:17 AM
09-27-2002 06:17 AM
Re: Selection option within a script
remove the "return" in the "all_printers" function. It was only there for me to run the script to check for syntax errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2002 08:12 AM
09-27-2002 08:12 AM
Re: Selection option within a script
Where you say the statement:
#This is where your current syntax goes.
# Ex: hpnpadmin ${fulllist} If you can send
# all devices into the command?
What do you mean by that statement, and what part of my original script do I put in there.
Sorry but im not clear on that part of it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2002 08:14 AM
09-27-2002 08:14 AM
Re: Selection option within a script
It's also giving me an error that says:
select_on parameter not set.
I thought that part was set by the script already.