Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

this is day one for me for bash. perhaps this question has already been asked, but i've tried google and have come up empty. maybe because i don't know how to articulate my question.

i have a custom/inhouse linux program that prompts the end user with a bunch of questions... and ultimately uses those questions to set up some servers. now i want to automate this so that a bash script will call the bin file and provide static answers. ideally i want to save the answers in a file, in the order that they are asked, and just feed it to the program.

Right now, I've been looking at sample scripts that read files. But I can't find an example that combines using file input and supplying answers to a program.

any pointers would be appreciated.

EDIT 1

I've tried to do the following:

#!/bin/bash
echo "This script is about to call mytestapp"
mytestapp
printf 'lab\nci1\n6cr\n197\n0\n252\n888\n4\n\nAmerica/Toronto\n
~

When I run this, the "mytestapp" program launchs, but it sits there at the first question, waiting for input like this:

dev1:~# sh /tmp/test_wrapper.sh 
This script is about to call mytestapp
Enter the 3-letter location code (e.g. usa):

And the printf statement in the script never kicks in.

EDIT 2

i found my mistake. needed to pipe the params into the app:

 printf 'lab\nci1\n6cr\n197\n0\n252\n888\n4\n\nAmerica/Toronto\n' | mytestapp
share|improve this question
2  
Maybe this post can help: stackoverflow.com/questions/3804577/… – Douglas Ohlhorst Jun 9 '16 at 18:33
    
@DouglasOhlhorst thanks for the link! It definitely got me started with some ideas. Although please the edit i made to my question. – Happydevdays Jun 9 '16 at 18:54

You can use your printf command, but it's usually easier to understand and maintain using a here-document:

mytestapp <<EOF
lab
i1
6cr
197
0
252
888
4

America/Toronto
EOF
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.