Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Taking input from text file for ssh command 1

Status
Not open for further replies.

stevio

Vendor
Jul 24, 2002
78
AU
Hi all,

I have a very simple script which sshes into each server (cat each server in myhosts file) and runs a command "install.sh"

install.sh then starts an install which asks for user input. The input always the same for all servers and in the same order, eg what is the server ip?, tcp port?, install?

Question - How do I store the user input into a text file (so that they can modify the variables), and also can be used by testscript.sh to insert the info. Currently, everytime the install.sh runs, I have to type in the info manually.

text file for input would look like the following:
----------------------
serverip=10.0.0.1
port=2000
install=Y
etc
----------------------

testscript.sh script thus far
Code:
for host in `cat myhosts`
do
echo running test install to $host
  scp -pr /tmp/install.sh root@$myhost:/
  ssh $myhost /tmp/install.sh
done

Any help would be much appreciated, and hopefully useful for others
Regards
Stevio
 
Have you tried modifying the /tmp/install.sh to get its input from a file instead of asking for user input. Then you could copy the file (along with install.sh) to $host. A different file could be prepared for each server and called /tmp/${host}_install_params.

I hope that helps to get the thought processes working.

Mike
 
Mike,

I'd rather not change install.sh (support issues), but instead use testscript (script which kicks off install.sh) to grab variables from a config file, and feed that into the prompts from install.sh.

So, sequence of events.

testscript kicks off
cats the first host in myhost file
copies install.sh to remote server
run install.sh
automatically enter info in the correct sequence from config file. Script can enter info in a certain order, or check for the prompting question.

Stevio
 
Hi,

did you try to redirect the input of install.sh in your testscript, something like
Code:
ssh $myhost "/tmp/install.sh < install.txt"
?
This may or may not work; if it doesn't, you might want to look at expect

hope this helps
 
Thanx hoinz for putting me on the right track. I think Expect will do the job
A star for hoinz!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top