- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: A test command parameter is not valid.
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
Discussions
Discussions
Forums
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
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
тАО04-11-2009 08:31 PM
тАО04-11-2009 08:31 PM
[BEGIN SCRIPT OUTPUT]
/home/user/scripts
Sat Apr 11 22:37:28 CDT 2009
This script adds to, and deletes printers from HP-UX servers using Jetdirect.
There are also options to delete a queue, or queues only.
Printer Script Menu
1. Add A Single Printer To One Or More Servers.
(Deletes the queue first if it already exists.)
2. Delete A Single Printer From One Or More Servers.
3. Add Multiple Printers To One Or More Servers.
(Deletes the queue first if it already exists.)
4. Delete Multiple Printers From One Or More Servers.
5. Add A Zebra Printer To One Or More Valid Servers.
6.Exit
V 1.7 4/11/2009
Enter your selection:5
The printer must have an entry in /etc/hosts of the server(s) you plan
to add the zebra printer to if the printer is to work.
Does the printer have an entry in /etc/hosts of the server(s) you plan
to add the zebra printer to?
Enter 'y' or 'n':y
Enter printer queue name:test
Enter server host names separated by a blank space. ex.(server1 server2 server3):
server15
One or more hostnames you have selected is not a valid server!!!
[END SCRIPT OUTPUT]
The problem comes when I put in one server that is valid, and one that is not. In the output below, server15 is invalid, while server1 is valid. I get a test parameter error:
[BEGIN SCRIPT OUTPUT]
/home/user/scripts
Sat Apr 11 22:38:47 CDT 2009
This script adds to, and deletes printers from HP-UX servers using Jetdirect.
There are also options to delete a queue, or queues only.
Printer Script Menu
1. Add A Single Printer To One Or More Servers.
(Deletes the queue first if it already exists.)
2. Delete A Single Printer From One Or More Servers.
3. Add Multiple Printers To One Or More Servers.
(Deletes the queue first if it already exists.)
4. Delete Multiple Printers From One Or More Servers.
5. Add A Zebra Printer To One Or More Valid Servers.
6.Exit
V 1.7 4/11/2009
Enter your selection:5
The printer must have an entry in /etc/hosts of the server(s) you plan
to add the zebra printer to if the printer is to work.
Does the printer have an entry in /etc/hosts of the server(s) you plan
to add the zebra printer to?
Enter 'y' or 'n':y
Enter printer queue name:test
Enter server host names separated by a blank space. ex.(server1 server2 server3):
server15 server1
NEWtlg_printer.sh[34]: server1: A test command parameter is not valid.
One or more hostnames you have selected is not a valid server!!!
[END SCRIPT OUTPUT]
Here is the code that comprises option 5 in the menu. Please help me correct this, or find a better way to implement this:
[CODE]
function zebra_printer_func
{
echo
echo "The printer must have an entry in /etc/hosts of the server(s) you plan"
echo "to add the zebra printer to if the printer is to work."
echo
echo "Does the printer have an entry in /etc/hosts of the server(s) you plan"
echo "to add the zebra printer to?"
print -n "Enter 'y' or 'n':"
read CHOICE
case "$CHOICE" in
y|yes|Yes|YES) echo
continue ;;
n|no|No|NO) echo
echo "Please correct before continuing!!"
sleep 04
main_menu_func ;;
*) clear
zebra_printer_func ;;
esac
echo
print -n "Enter printer queue name:"
read QNAME
echo
echo "Enter server host names separated by a blank space. ex.(server1 server2 server3):"
read HNAME
echo
if [ $HNAME = server1 -o $HNAME = server2 -o $HNAME = server3 -o $HNAME = server4 -o $HNAME = server5 ]
then
continue
else
echo 'One or more hostnames you have selected is not a valid server!!!'
sleep 04
main_menu_func
fi
for i in $HNAME ; do
(
echo "ssh $HNAME -n /usr/sbin/lpadmin -p$QNAME -v/dev/null -mrmodel -ob3 -ocmrcmodel -osmrsmodel -orc -orm$QNAME -orp$QNAME"
ssh $HNAME "/usr/sbin/lpshut ; /usr/sbin/lpadmin -p$QNAME -v/dev/null -mrmodel -ob3 -ocmrcmodel -osmrsmodel -orc -orm$QNAME -orp$QNAME ; \
/usr/sbin/accept $QNAME ; /usr/bin/enable $QNAME ; /usr/sbin/lpsched"
)
done
}
[/CODE]
Solved! Go to Solution.
- Tags:
- Test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2009 08:32 PM
тАО04-11-2009 08:32 PM
Re: A test command parameter is not valid.
http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2009 10:36 PM
тАО04-11-2009 10:36 PM
Solutionspace-separated, right?
What does this look like:?
if [ $HNAME = server1 [...]
Perhaps something like:
if [ server1 server2 server3 = server1 [...]
Too many tokens for the "[" ("test") syntax.
You seem to be expecting HNAME to be one name
("if [ $HNAME = server1 ") and all the names
("for i in $HNAME"). It seems unlikely to
work both ways.
1. Use "-x" or "-v" to get the shell to tell
you what it's doing.
2. Trust no one, especially users. When a
variable contains a user-supplied value, you
should probably use (quoted) "$variable"
instead of (plain) $variable, so that you
will be treating the whole thing as an entity
rather than as some mess of unknown content
supplied by the user, unless you actually
wish to break it into pieces, as in
for x in $variable ; do
.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2009 11:34 PM
тАО04-11-2009 11:34 PM
Re: A test command parameter is not valid.
if [ "$HNAME" = server1 -o ... ];
The pedantic level to allow for leading "-":
if [ X"$HNAME" = Xserver1 -o ... ];
If you have lots of tests you may want to use case:
case $HNAME in
server1|server2|server3|...)
: ;;
*)
echo 'One or more hostnames you have selected is not a valid server!!!' ;;
And if you want to do several names, you should use a for statement.
You might look into a select statement, that will list all of the valid selections, so there is no need to check.
select HNAME in server1 server2; do
... # check for validity
done
This only does one at a time.
- Tags:
- quoting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2009 06:17 AM
тАО04-12-2009 06:17 AM
Re: A test command parameter is not valid.
As noted, develop a defensive posture when coding 'test's in the shell by double quoting your variables:
# X= ;[ ${X} = something ] && echo ${X} || echo "tell me what"
sh: test: Specify a parameter with this command.
tell me what
# X= ;[ "${X}" = something ] && echo ${X} || echo "tell me what"
tell me what
Secondly, use 'typeset' to enhance your code. Typeseting variables to integers (with '-i') improves arithmetic performanace. Typeseting with '-l' lowercases the variable contents and makes for less tests in code like:
...
typeset -l CHOICE
read CHOICE
case ${CHOICE} in
y|yes ) echo OK
;;
* ) echo try again
;;
esac
...
Notice that "yes" or "Yes" or "YES" or "yEs", etc. are now equally valid without having to state every permutation.
Regards!
...JRF...
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2009 08:36 PM
тАО04-12-2009 08:36 PM
Re: A test command parameter is not valid.
http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html#post302306461
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-12-2009 10:51 PM
тАО04-12-2009 10:51 PM
Re: A test command parameter is not valid.
You need to either combined the for loops or have them do the same:
for HNAME in ${HNAMES}; do
# checking here
...
main_menu_func
done
# this will have the last one
echo ${HNAME} # Checking the HNAME variable
# Change names here:
for HNAME in ${HNAMES}; do
The call to main_menu_func in the first for loop may cause a problem if you don't return or exit that function. It is probably better to combine the loops so you still do the valid servers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-13-2009 04:00 AM
тАО04-13-2009 04:00 AM
Re: A test command parameter is not valid.
In your external link you wrote:
> It only sees my last list item, and only sets it as the variable
You have:
for HNAME in ${HNAMES}
...
for i in $HNAME
...
If you want to walk the list of ${HNAMES} twice, then at least use the same list :-) The second statement should/could be:
for HNAME in ${HNAMES}
...not the last element ${HNAME} from the first iteration.
Regards!
...JRF...