1

I am trying to run a bash script which downloads and runs another script. The second script contains questions that must be answered by input. I have already attempted to use expect but it fails because the downloaded script runs in bash so it will not spawn the script.

Is there another way to pass input to the script after it downloads and runs?

Here is my script:

#!/bin/bash
mkdir ~/.aws
echo "[default]" >> ~/.aws/credentials
echo "aws_access_key_id = <key here>" >> ~/.aws/credentials
echo "aws_secret_access_key = <key here>" >> ~/.aws/credentials
curl https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py -o LinuxConfigurationScript.sh
chmod +x LinuxConfigurationScript.sh
./LinuxConfigurationScript.sh -r us-east-1
6
  • Would it be feasible to modify the LinuxConfigurationScript.sh with whatever values you need, and remove the input directives, before executing? I'm assuming that you want to automate this, and that the answers aren't simply "yes". Otherwise, you could just do yes | LinuxConfigurationScript.sh -r us-east-1. Commented Jul 7, 2016 at 19:27
  • That could be a thought but I'm not the keeper of the script that's being downloaded and things can change in that script at anytime. You would be correct in that I want to automate this process. The script asks for AWS credentials along with several other questions around region of deployment and configuration of the install. For short, the input could be a number of things required but they would be static for each deployment I need to run. Commented Jul 7, 2016 at 19:33
  • I was thinking about using something like downloading the script once, and then downloading the copy from your own, modified source later. Other than expect, I'm not certain of another such tool. If I'm automating something, though, I would rather have a single, stable file than downloading a script that may have changed, anyway. Commented Jul 7, 2016 at 19:53
  • Have you considered using the --non-interactive option that appears to be available for that script? Also, the downloaded script is python, not bash. Commented Jul 7, 2016 at 19:56
  • @jordanm, I stand corrected, yes it is Python. I have attempted the non-interactive script with no success. root@77889ca764d0:/# ./LinuxConfigurationScript.sh -n -r us-east-1 ERROR: Missing required arguments. Please run with --help for details. Commented Jul 7, 2016 at 20:01

1 Answer 1

3

Try this:

./LinuxConfigurationScript.sh -r us-east-1 <<EOF
command 1
command 2
EOF

Ok let's do a full example:

Here is my first script test.sh who ask several questions (your LinuxConfigurationScript.sh equivalent)

read -p "Question 1?" ans
echo $ans
read -p "Question 2?" ans
echo $ans
read -p "Question 3?" ans
echo $ans
read -p "Question 4?" ans
echo $ans

Here is my second script test2.sh who call the first one and answer all questions:

./test.sh <<EOF
answer 1
answer 2
answer 3
answer 4
EOF

And the alternative in one line:

{ echo "answer 1"; echo "answer 2"; echo "answer 3"; echo "answer 4"; } | ./test.sh
1
  • thanks for the answer though this didn't work for me. I instead used a bash script which called on the expect script. Not ideal but it works. Commented Jul 12, 2016 at 13:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.