Giving Input in a script

Hi,

I am a newbie to scripting. I want to know something..Is there any way that I can do this?

Here is the thing.. there are so many printer queues in which i need to change a certain option.. am using the hppi utility and i need to modify the printer configuration individually going to each printer and change ...
What I am doing right now is :
hppi, then entering option 1, then entering option 3 to modify the settings, giving the printer queue name and then changing the parameter.

What i want to know is :
Is there any way that I can enter the values 1 and 3 and the printer name in a script?? Then I would select the setting, change it ??

Thanks in advance ... :slight_smile:

You can programatically answer program prompts, in a script this is called a here document:
I have not used hppi, so I don't know what you mean by select. Once you start a here doc, ALL of the answers have to be pre-programmed. I'll create something for you to work with - YOU need to change it.

#!/bin/ksh
# set_pr.sh
# $1 == printer name
# $2 == printer setting to select  
hppi << EOF
1
3
"$1"
"$2"
EOF

execute

chmod +x set_pr.sh

so you can run the script

usage: ./set_pr.sh printer34 OptionA

If you need help with changing the script let us know.

1 Like

Thanks Jim..that worked :slight_smile:
Have another problem here... As i said, there are a lot of inputs that we need to give..if it doesn't get an input it seems to going into an infinite loop..is there any way to stop it??

hi.. try this...

if [ $# != 2 ]
then
        echo "incorrect number of arguments. Exitting !!!"
        exit 1;
fi

$# = the number of arguments that you are passing in the script.
here i have considered that i have only 2 arguments passing..
If there are say 5 arguments, the condition will look like -

if [ $# != 5 ]
then
        echo "incorrect number of arguments. Exitting !!!"
        exit 1;
fi

so the final code will be as follows :

 
#!/bin/ksh
# set_pr.sh
# $1 == printer name
# $2 == printer setting to select  
if [ $# != 5 ]
then
        echo "incorrect number of arguments. Exitting !!!"
        exit 1;
fi
hppi << EOF
1
3
"$1"
"$2"
EOF

If the desired number of arguments are not entered, the shell will quit stating this error:

sh set_pr.sh
incorrect number of arguments. Exitting !!!

Regards,
A!

1 Like