<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: A test command parameter is not valid. in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399393#M681871</link>
    <description>Having more fun with the script.  &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html#post302306461" target="_blank"&gt;http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html#post302306461&lt;/A&gt;</description>
    <pubDate>Mon, 13 Apr 2009 03:36:21 GMT</pubDate>
    <dc:creator>Patrick Ware_1</dc:creator>
    <dc:date>2009-04-13T03:36:21Z</dc:date>
    <item>
      <title>A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399388#M681866</link>
      <description>&lt;!--!*#--&gt;In the script output below I choose a menu option (5) that adds Zebra printers to servers.  I have a if-then-else statement setup to compare the server name entered against valid server names.  If a server that is not valid is entered, then the script tells the user that the server selected is not a valid server, and exits, as shown below:&lt;BR /&gt;&lt;BR /&gt;[BEGIN SCRIPT OUTPUT]&lt;BR /&gt;/home/user/scripts&lt;BR /&gt;Sat Apr 11 22:37:28 CDT 2009&lt;BR /&gt;This script adds to, and deletes printers from HP-UX servers using Jetdirect.&lt;BR /&gt;There are also options to delete a queue, or queues only.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;              Printer Script Menu&lt;BR /&gt;&lt;BR /&gt;                1. Add A Single Printer To One Or More Servers.&lt;BR /&gt;                   (Deletes the queue first if it already exists.)&lt;BR /&gt;&lt;BR /&gt;                2. Delete A Single Printer From One Or More Servers.&lt;BR /&gt;&lt;BR /&gt;                3. Add Multiple Printers To One Or More Servers.&lt;BR /&gt;                   (Deletes the queue first if it already exists.)&lt;BR /&gt;&lt;BR /&gt;                4. Delete Multiple Printers From One Or More Servers.&lt;BR /&gt;&lt;BR /&gt;                5. Add A Zebra Printer To One Or More Valid Servers.&lt;BR /&gt;&lt;BR /&gt;                6.Exit&lt;BR /&gt;&lt;BR /&gt;             V 1.7                              4/11/2009&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enter your selection:5&lt;BR /&gt;&lt;BR /&gt;The printer must have an entry in /etc/hosts of the server(s) you plan&lt;BR /&gt;to add the zebra printer to if the printer is to work.&lt;BR /&gt;&lt;BR /&gt;Does the printer have an entry in /etc/hosts of the server(s) you plan&lt;BR /&gt;to add the zebra printer to?&lt;BR /&gt;Enter 'y' or 'n':y&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enter printer queue name:test&lt;BR /&gt;&lt;BR /&gt;Enter server host names separated by a blank space. ex.(server1 server2 server3):&lt;BR /&gt;server15&lt;BR /&gt;&lt;BR /&gt;One or more hostnames you have selected is not a valid server!!!&lt;BR /&gt;&lt;BR /&gt;[END SCRIPT OUTPUT]&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;[BEGIN SCRIPT OUTPUT]&lt;BR /&gt;/home/user/scripts&lt;BR /&gt;Sat Apr 11 22:38:47 CDT 2009&lt;BR /&gt;This script adds to, and deletes printers from HP-UX servers using Jetdirect.&lt;BR /&gt;There are also options to delete a queue, or queues only.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;              Printer Script Menu&lt;BR /&gt;&lt;BR /&gt;                1. Add A Single Printer To One Or More Servers.&lt;BR /&gt;                   (Deletes the queue first if it already exists.)&lt;BR /&gt;&lt;BR /&gt;                2. Delete A Single Printer From One Or More Servers.&lt;BR /&gt;&lt;BR /&gt;                3. Add Multiple Printers To One Or More Servers.&lt;BR /&gt;                   (Deletes the queue first if it already exists.)&lt;BR /&gt;&lt;BR /&gt;                4. Delete Multiple Printers From One Or More Servers.&lt;BR /&gt;&lt;BR /&gt;                5. Add A Zebra Printer To One Or More Valid Servers.&lt;BR /&gt;&lt;BR /&gt;                6.Exit&lt;BR /&gt;&lt;BR /&gt;             V 1.7                              4/11/2009&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enter your selection:5&lt;BR /&gt;&lt;BR /&gt;The printer must have an entry in /etc/hosts of the server(s) you plan&lt;BR /&gt;to add the zebra printer to if the printer is to work.&lt;BR /&gt;&lt;BR /&gt;Does the printer have an entry in /etc/hosts of the server(s) you plan&lt;BR /&gt;to add the zebra printer to?&lt;BR /&gt;Enter 'y' or 'n':y&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Enter printer queue name:test&lt;BR /&gt;&lt;BR /&gt;Enter server host names separated by a blank space. ex.(server1 server2 server3):&lt;BR /&gt;server15 server1&lt;BR /&gt;NEWtlg_printer.sh[34]: server1: A test command parameter is not valid.&lt;BR /&gt;One or more hostnames you have selected is not a valid server!!!&lt;BR /&gt;[END SCRIPT OUTPUT]&lt;BR /&gt;&lt;BR /&gt;Here is the code that comprises option 5 in the menu.  Please help me correct this, or find a better way to implement this:&lt;BR /&gt;&lt;BR /&gt;[CODE]&lt;BR /&gt;function zebra_printer_func&lt;BR /&gt;         {&lt;BR /&gt;echo&lt;BR /&gt;echo "The printer must have an entry in /etc/hosts of the server(s) you plan"&lt;BR /&gt;echo "to add the zebra printer to if the printer is to work."&lt;BR /&gt;echo&lt;BR /&gt;echo "Does the printer have an entry in /etc/hosts of the server(s) you plan"&lt;BR /&gt;echo "to add the zebra printer to?"&lt;BR /&gt;print -n "Enter 'y' or 'n':"&lt;BR /&gt;read CHOICE&lt;BR /&gt;case "$CHOICE" in&lt;BR /&gt;     y|yes|Yes|YES) echo&lt;BR /&gt;                    continue ;;&lt;BR /&gt;        n|no|No|NO) echo&lt;BR /&gt;                    echo "Please correct before continuing!!"&lt;BR /&gt;                    sleep 04&lt;BR /&gt;                    main_menu_func ;;&lt;BR /&gt;                 *) clear&lt;BR /&gt;                    zebra_printer_func ;;&lt;BR /&gt;esac&lt;BR /&gt;echo&lt;BR /&gt;print -n "Enter printer queue name:"&lt;BR /&gt;read QNAME&lt;BR /&gt;echo&lt;BR /&gt;echo "Enter server host names separated by a blank space. ex.(server1 server2 server3):"&lt;BR /&gt;read HNAME&lt;BR /&gt;echo&lt;BR /&gt;if [ $HNAME = server1 -o $HNAME = server2 -o $HNAME = server3 -o $HNAME = server4 -o $HNAME = server5 ]&lt;BR /&gt;  then&lt;BR /&gt;   continue&lt;BR /&gt;else&lt;BR /&gt;  echo 'One or more hostnames you have selected is not a valid server!!!'&lt;BR /&gt;  sleep 04&lt;BR /&gt;  main_menu_func&lt;BR /&gt;fi&lt;BR /&gt;for i in $HNAME ; do&lt;BR /&gt; (&lt;BR /&gt;echo "ssh $HNAME -n /usr/sbin/lpadmin -p$QNAME -v/dev/null -mrmodel -ob3 -ocmrcmodel -osmrsmodel -orc -orm$QNAME -orp$QNAME"&lt;BR /&gt;ssh $HNAME "/usr/sbin/lpshut ; /usr/sbin/lpadmin -p$QNAME -v/dev/null -mrmodel -ob3 -ocmrcmodel -osmrsmodel -orc -orm$QNAME -orp$QNAME ; \&lt;BR /&gt;/usr/sbin/accept $QNAME ; /usr/bin/enable $QNAME ; /usr/sbin/lpsched"&lt;BR /&gt; )&lt;BR /&gt;done&lt;BR /&gt;         }&lt;BR /&gt;[/CODE]</description>
      <pubDate>Sun, 12 Apr 2009 03:31:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399388#M681866</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2009-04-12T03:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399389#M681867</link>
      <description>This link has a better visual representation of what is going on:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html" target="_blank"&gt;http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html&lt;/A&gt;</description>
      <pubDate>Sun, 12 Apr 2009 03:32:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399389#M681867</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2009-04-12T03:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399390#M681868</link>
      <description>&lt;!--!*#--&gt;Look at what's in HNAME.  Multiple names,&lt;BR /&gt;space-separated, right?&lt;BR /&gt;&lt;BR /&gt;What does this look like:?&lt;BR /&gt;&lt;BR /&gt;if [ $HNAME = server1 [...]&lt;BR /&gt;&lt;BR /&gt;Perhaps something like:&lt;BR /&gt;&lt;BR /&gt;if [ server1 server2 server3 = server1 [...]&lt;BR /&gt;&lt;BR /&gt;Too many tokens for the "[" ("test") syntax.&lt;BR /&gt;&lt;BR /&gt;You seem to be expecting HNAME to be one name&lt;BR /&gt;("if [ $HNAME = server1 ") and all the names&lt;BR /&gt;("for i in $HNAME").  It seems unlikely to&lt;BR /&gt;work both ways.&lt;BR /&gt;&lt;BR /&gt;1.  Use "-x" or "-v" to get the shell to tell&lt;BR /&gt;you what it's doing.&lt;BR /&gt;&lt;BR /&gt;2.  Trust no one, especially users.  When a&lt;BR /&gt;variable contains a user-supplied value, you&lt;BR /&gt;should probably use (quoted) "$variable"&lt;BR /&gt;instead of (plain) $variable, so that you&lt;BR /&gt;will be treating the whole thing as an entity&lt;BR /&gt;rather than as some mess of unknown content&lt;BR /&gt;supplied by the user, unless you actually&lt;BR /&gt;wish to break it into pieces, as in&lt;BR /&gt;    for x in $variable ; do&lt;BR /&gt;.</description>
      <pubDate>Sun, 12 Apr 2009 05:36:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399390#M681868</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-04-12T05:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399391#M681869</link>
      <description>&lt;!--!*#--&gt;As Steven said multiple names will mess you up.  If you want to solve your error with test(1) you should do some of the following:&lt;BR /&gt;if [ "$HNAME" = server1 -o ... ];&lt;BR /&gt;&lt;BR /&gt;The pedantic level to allow for leading "-":&lt;BR /&gt;if [ X"$HNAME" = Xserver1 -o ... ];&lt;BR /&gt;&lt;BR /&gt;If you have lots of tests you may want to use case:&lt;BR /&gt;case $HNAME in&lt;BR /&gt;server1|server2|server3|...)&lt;BR /&gt;  : ;;&lt;BR /&gt;*)&lt;BR /&gt;  echo 'One or more hostnames you have selected is not a valid server!!!' ;;&lt;BR /&gt;&lt;BR /&gt;And if you want to do several names, you should use a for statement.&lt;BR /&gt;&lt;BR /&gt;You might look into a select statement, that will list all of the valid selections, so there is no need to check.&lt;BR /&gt;&lt;BR /&gt;select HNAME in server1 server2; do&lt;BR /&gt;...  # check for validity&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;This only does one at a time.</description>
      <pubDate>Sun, 12 Apr 2009 06:34:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399391#M681869</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-04-12T06:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399392#M681870</link>
      <description>&lt;!--!*#--&gt;Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;As noted, develop a defensive posture when coding 'test's in the shell by double quoting your variables:&lt;BR /&gt;&lt;BR /&gt;# X= ;[ ${X} = something ] &amp;amp;&amp;amp; echo ${X} || echo "tell me what"&lt;BR /&gt;sh: test: Specify a parameter with this command.&lt;BR /&gt;tell me what&lt;BR /&gt;&lt;BR /&gt;# X= ;[ "${X}" = something ] &amp;amp;&amp;amp; echo ${X} || echo "tell me what"&lt;BR /&gt;tell me what&lt;BR /&gt;&lt;BR /&gt;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:&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;typeset -l CHOICE&lt;BR /&gt;read CHOICE&lt;BR /&gt;case ${CHOICE} in&lt;BR /&gt;    y|yes ) echo OK&lt;BR /&gt;    ;;&lt;BR /&gt;    *     ) echo try again&lt;BR /&gt;    ;;&lt;BR /&gt;esac&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;Notice that "yes"  or "Yes" or "YES" or "yEs", etc. are now equally valid without having to state every permutation.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 12 Apr 2009 13:17:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399392#M681870</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-12T13:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399393#M681871</link>
      <description>Having more fun with the script.  &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html#post302306461" target="_blank"&gt;http://www.unix.com/shell-programming-scripting/107003-test-command-parameter-not-valid.html#post302306461&lt;/A&gt;</description>
      <pubDate>Mon, 13 Apr 2009 03:36:21 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399393#M681871</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2009-04-13T03:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399394#M681872</link>
      <description>&lt;!--!*#--&gt;&amp;gt;Having more fun with the script.&lt;BR /&gt;&lt;BR /&gt;You need to either combined the for loops or have them do the same:&lt;BR /&gt;for HNAME in ${HNAMES}; do&lt;BR /&gt;   # checking here&lt;BR /&gt;   ...&lt;BR /&gt;      main_menu_func&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;# this will have the last one&lt;BR /&gt;echo ${HNAME} # Checking the HNAME variable &lt;BR /&gt;&lt;BR /&gt;# Change names here:&lt;BR /&gt;for HNAME in ${HNAMES}; do&lt;BR /&gt;&lt;BR /&gt;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.</description>
      <pubDate>Mon, 13 Apr 2009 05:51:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399394#M681872</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-04-13T05:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: A test command parameter is not valid.</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399395#M681873</link>
      <description>HI:&lt;BR /&gt;&lt;BR /&gt;In your external link you wrote:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; It only sees my last list item, and only sets it as the variable&lt;BR /&gt;&lt;BR /&gt;You have:&lt;BR /&gt;&lt;BR /&gt;for HNAME in ${HNAMES}&lt;BR /&gt;...&lt;BR /&gt;for i in $HNAME&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;If you want to walk the list of ${HNAMES} twice, then at least use the same list :-)  The second statement should/could be:&lt;BR /&gt;&lt;BR /&gt;for HNAME in ${HNAMES}&lt;BR /&gt;&lt;BR /&gt;...not the last element ${HNAME} from the first iteration.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Mon, 13 Apr 2009 11:00:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/a-test-command-parameter-is-not-valid/m-p/4399395#M681873</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-04-13T11:00:49Z</dc:date>
    </item>
  </channel>
</rss>

