Automating Interactive script

I have a script that will install software on all remote host. At the end of the script it starts the install.sh part and goes into a interactive mode asking Yes or No questions and prompting to add a username and password. My question is how can I script this so that these questions are answered automatically? Here is my script.

#!/bin/ksh
PATH=/usr/bin:/usr/sbin:/opt/local/bin:/usr/local/bin
PGM=`basename $0`
HOSTS=$1

[[ -z $HOSTS ]] && HOSTS="`grep -v \# /opt/local/etc/hosts|grep -i atl380g5test|nawk '{print $1}'`"

echo "$PGM: Installing Sophos AntiVirus Software"
for host in $HOSTS
do
printf "o PROCESSING HOST: %-20s\n" $host
ping $host 1>/dev/null 2>&1;
if (( $? )) ; then
echo "--Cannot contact host $host";
else
scp /admin/install.sophos.tar $host:/opt/install.sophos.tar
echo " --installing Sophos Antivirus software on $host"
ssh $host 'cd /opt/ ; tar -xvf install.sophos.tar; /opt/sofos/install.sh; rm -r install.sophos.tar
echo " The script will ask you a series of Y or N questions. press enter to start"
fi;
done

The scripts starts the install part then ask a series of questions I want to automate and need assistance with. thanks..

 	  o you accept the licence? Yes\(Y\)/No\(N\) [N] 

> Y
Where do you want to install Sophos Anti-Virus? [/opt/sophos-av]
> enter
Sophos Anti-Virus GUI is accessible at The UNIX and Linux Forums - Learn UNIX and Linux from Experts from your web browser.
You must now enter a username/password for Sophos Anti-Virus GUI. If you enter a blank password, the Sophos Anti-Virus GUI will be
disabled.

Username for Sophos Anti-Virus GUI? [admin]
>
Password for Sophos Anti-Virus GUI?
>test1
Re-enter the same password.
>test1

Do you want to enable remote management? Yes(Y)/No(N) [Y]
>
Do you want to enable on-access scanning? Yes(Y)/No(N) [Y]
ar'

Unless your application installation accepts a noask file, and since multiple responses are needed (otherwise echo y | install.sh would do) probably your best bet is to use expect.

You may be able to use a co-process.

Check out: https://rz-static.uni-hohenheim.de/betriebssysteme/unix/aix/aix_4.3.3_doc/base_doc/usr/share/man/info/en_US/a_doc_lib/aixuser/usrosdev/input_output_redir_korn.htm

Look under the section, coprocess facility. Hope that helps.

You can also redirect input from the program "yes", which will output "y<newline" until the end of time.

Can someone post some examples on this? thx

"yes" is a Linux command everybody is suggesting you.

If you have not got yet, execute 'yes' in your terminal which will just print y indefinitely .. that is what you wanted.

yes | your-program

which will pipe the y to your-program required number of times. ??

Got it ?

Not everybody is suggesting "yes", because it wouldn't work in this particular case. If you look at the OP input, you'll notice that he needs to input different text other than just "yes"; it asks for a specific username and a password, a path. That is why I suggested expect.

fine, i accept your point that, expect is the good choice if you want to give different inputs to an automated job.