LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Automating Interactive script (http://www.linuxquestions.org/questions/programming-9/automating-interactive-script-719586/)

soupbone38 04-16-2009 09:37 AM

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 http://localhost:8081/ 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'

miedward 04-16-2009 09:50 AM

Try "here documents". I have used them to good effect for things like this, though they don't allways work as intended, so some experimentation may be required.

Try something like.

#!/bin/bash
install.sh <<LimitString
Y
enter
admin
test1
test1
Y
Y
LimitString

They work the same way in most unix shells (and perl), but your millage may vary.
http://www.tldp.org/LDP/abs/html/here-docs.html


All times are GMT -5. The time now is 09:20 AM.