LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-16-2009, 09:37 AM   #1
soupbone38
LQ Newbie
 
Registered: Feb 2009
Posts: 8

Rep: Reputation: 0
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'
 
Old 04-16-2009, 09:50 AM   #2
miedward
Member
 
Registered: Feb 2007
Distribution: RHEL 4, SOLARIS 10
Posts: 91

Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM
Automating sftp using a shell script bhandu Linux - Newbie 3 07-17-2007 01:56 AM
automating lynx in a shell script yimboli Programming 15 04-04-2007 02:15 AM
Automating a playlist using shell script... DesiLILO Linux - Newbie 4 04-02-2004 11:03 PM
FTP Script (Automating) noodle123 Linux - General 2 10-16-2002 08:17 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration