Operating System - HP-UX
1752800 Members
5734 Online
108789 Solutions
New Discussion юеВ

Parameter help inside script.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

Parameter help inside script.

Hello all

I am trying to figure out the error i am getting from the script below, i understand its a parameter not set but I thought that as part of the script executes it will set that parameter during execution. Basically with this script I am trying to allow someone to query all printers on system or select a particular printer for the check.

can anyone shed some light on this.

Error: ./jdpstatus[80]: select_on: parameter not set


#! /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=/home/fgrosb01
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.
##################################################################################
# Defaults

PS3="Please select desired printer: "
fulllist="`cd /etc/lp/interface;ls`"

all_printers ()
{
hpnpadmin ${fulllist}
}

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

hpnpadmin ${prtlist}
}

# Main

if test ${#} -ne 0
then
while getopts :s option
do
case ${option} in
s) select_on="Y";;
?) echo "Usage: ${0} [<-s>]"
exit 4 ;;
esac
done
fi

[ "${select_on}" = 'N' ] && all_printers || single_printer

exit 0
mvitux01@/home/fgrosb01#

10 REPLIES 10
Rodney Hills
Honored Contributor
Solution

Re: Parameter help inside script.

This section of code that checks for no arguments-

if test ${#} -ne 0
...
fi

will bypass the while loop and select_on will not be set.

HTH

-- Rod Hills
There be dragons...
Robin Wakefield
Honored Contributor

Re: Parameter help inside script.

Hi Frank,

You've got "set -u" which means treat unset variables as an error when substituting, and in your test at around line 80, select_on hasn't necessarily been set, hence the error. Just initialise it first.

Rgds, Robin
fg_1
Trusted Contributor

Re: Parameter help inside script.

ok all

as per your suggestion robin, i moved the statement containing the select_on variable up in the script, now the script just passes thru with no input asked for or output given.

any clues?

mvitux01@/home/fgrosb01# ./jdpstatus
#! /usr/bin/ksh -v

# This script is utilized to gather printer information on all print queue's installed
# on a system using the hpnpadmin command.

# Environmental section

BASEDIR=/home/fgrosb01
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
HP-UX (Version HPUX-b.11.00.01) 2002/09/30/11:17:12
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.
##################################################################################
# Defaults

PS3="Please select desired printer: "
fulllist="`cd /etc/lp/interface;ls`"

all_printers ()
{
hpnpadmin ${fulllist}
}

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

hpnpadmin ${prtlist}
}

[ "${select_on}" = 'N' ] && all_printers || single_printer
./jdpstatus[64]: single_printer: not found

# Main
if test ${#} -ne 0
then
while getopts :s option
do
case ${option} in
s) select_on="Y";;
?) echo "Usage: ${0} [<-s>]"
exit 4 ;;
esac
done
fi

exit 0
mvitux01@/home/fgrosb01#

Robin Wakefield
Honored Contributor

Re: Parameter help inside script.

Hi Frank,

"single_printer" is incorrect, it should be "select_printer".

I didn't actually mean to move the statement, just initialise select_on to "N", or whatever you need it to be at the beginning of the script.

Rgds, Robin
Rodney Hills
Honored Contributor

Re: Parameter help inside script.

I don't see "single_printer" defined.

-- Rod Hills
There be dragons...
fg_1
Trusted Contributor

Re: Parameter help inside script.

Ok guys

Were extremely close, everything works with the exception of when you select #1) All
you get an error, (listed below).

Each of the individual printer queue names work as needed, but I also have no need to have model.orig as a listed variable there but I can deal with that if I had to. the big thing here is the ALL option which should print the necessary info for #'s 4-6 in one listing.

1) ALL
2) Quit
3) model.orig
4) mv2itd05
5) mv2itd07
6) mv2itd08
Please select desired printer: 1
model.orig: Unknown printer
: Error sending SNMP request.
*** Can't find the session!
mvitux01@/home/fgrosb01#


mvitux01@/home/fgrosb01# more jdpstatus
#! /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

BASEDIR=/home/fgrosb01
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.
##################################################################################
# Defaults

PS3="Please select desired printer: "
fulllist="`cd /etc/lp/interface;ls`"

all_printers ()
{
hpnpadmin -iqS ${fulllist}
}

single_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

hpnpadmin -iqS ${prtlist}
}

[ "${select_on}" = 'N' ] && all_printers || single_printer

# Main
if test ${#} -ne 0
then
while getopts :s option
do
case ${option} in
s) select_on="Y";;
?) echo "Usage: ${0} [<-s>]"
exit 4 ;;
esac
done
fi

exit 0
mvitux01@/home/fgrosb01#

Rodney Hills
Honored Contributor

Re: Parameter help inside script.

In setting "fulllist", you do a

fulllist="`cd /etc/lp/interface;ls`"

Did you know a directory called "model.orig" exists in that folder? This could cause an unknown printer error.

I have found when debugging a script to put some echo commands to display key variables at key points. That way I don't "assume" the values are what I expect.

Good Luck

-- Rod Hills
There be dragons...
fg_1
Trusted Contributor

Re: Parameter help inside script.

Ok

Once I changed the FULLIST directory to:

fulllist="`cd /etc/lp/interface/model.orig;ls`"

The script will now return a value for the ALL function, but it is only the 1st printer that is listed, not all of the printers in the directory. As in the above post by me, option 1=all, option 4-6 are the individual printers, now when you select option 1, it only returns the info on the 1st printer.

Any ideas.


Rodney Hills
Honored Contributor

Re: Parameter help inside script.

I think you are assuming that hpnpadmin can take more than 1 printer on the command line.

If you were to look at the man page for hpnpadmin, you would find it only allows one printer.

To work around, do the following
echo ${prtlist} | xargs -n1 hpnpadmin

This will run hpnpadmin once for each printer.

Another debugging hint-
If you have a command you are unfamiliar with, try running it directly to see the results, instead of "assuming" the command works the way you think it should.

HTH

-- Rod Hills
There be dragons...