![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk/sed Command : Parse parameter file / send the lines to the ksh export command | rajan_san | Shell Programming and Scripting | 4 | 11-06-2008 01:29 PM |
| Passing Parameter in SED command | dsrookie | UNIX for Dummies Questions & Answers | 2 | 06-09-2008 01:25 AM |
| Help regarding Error message: A test command parameter is not valid | skyineyes | Shell Programming and Scripting | 5 | 06-29-2007 05:38 AM |
| Using of Top command as script parameter | elthox | Shell Programming and Scripting | 4 | 01-31-2007 01:21 PM |
| pwd: A specified flag is not valid for this command. | Paxton | UNIX for Dummies Questions & Answers | 2 | 08-29-2003 12:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
A test command parameter is not valid.
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:
Code:
/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!!!
Code:
/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!!!
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
}
|
|
||||
|
Thanks for your input. I've fixed the test error I was getting. Now I have another issue. Now when I enter two or more VALID servers, I get the a reply telling me that one or more of my server names are invalid. Here is the output:
Code:
/home/user/scripts
Sat Apr 12 12:34:14 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):
server1 server2
One or more hostnames you have selected is not a valid server!!!
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 HNAMES
echo
if [ "$HNAMES" = server1 -o "$HNAMES" = server2 -o "$HNAMES" = server3 -o "$HNAMES" = server4 -o "$HNAMES" = server5 ]
then
continue
else
echo 'One or more hostnames you have selected is not a valid server!!!'
sleep 04
main_menu_func
fi
for HNAME in $HNAMES ; 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
}
|
|
|||||
|
Hi
the error occours because when you write "server1 server2" $HNAME will be "server1 server2" and not "server1" "server2" so when you test you variable with the if statement, you are asking what follow: if [ "server1 server2 " = server1 ] and it will be always false. Tony before told you to use "for" to read your HNAME for SERVERS in $HNAME; do here you can put you if statement because you are reading one input for iteration done hope it helps Bye Bye ------------------------------------ Computers are like air-conditioners they stop working properly when you open windows |
|
|||||
|
As Sauron has said with the latest mod to the code HNAMES is going to equal "server1 server2"; the line:
Code:
for HNAME in $HNAMES ; do Code:
if [ "$HNAMES" = server1 -o "$HNAMES" = server2 -o "$HNAMES" = server3 -o "$HNAMES" = server4 -o "$HNAMES" = server5 ] Either that of you are going to have to test for all variations of "server1 server2", "server2 server1", "server1 server2 server3", etc! Last edited by TonyFullerMalv; 04-12-2009 at 04:14 PM.. |
|
||||
|
Ok, I tried that. The latest issue I am having is that now when I enter more than one valid server, it only keeps the last server in the list. I set up the script so that it would echo what the $HNAME is. See my example below :
Code:
/home/user/scripts
Sun Apr 12 23:30:21 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):
server1 server2 server3
server3 #It only sees my last list item, and only sets it as the variable
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 HNAMES
echo
for HNAME in ${HNAMES}
do
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
done
echo ${HNAME} #Checking the HNAME variable
exit #Inserted exit so that the script will stop here..
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
}
|
|
|||||
|
hi,
if you put "echo "$HNAME" out of the for cicle, it is obvious you will see just the last server the cicle reads. Try putting an echo "$HANME" inside the cicle. The second cicle (for i in $HNAME) it is wrong because $HNAME out of the first cicle takes the last value of the cicle, you should use (for i in $HNAMES) because $HNAMES is the user inserted list of servers. Bye |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|