0

I am a newb to Linux and AWS and I'm trying to figure out what should be a simple task. I have an instance of Amazon Linux running in EC2 and I'm trying to write a script that will start some new instances (same AMI). The script (called my_script) is as follows:

#!/bin/sh                    
ec2-describe-instances
ec2-run-instances ami-b66ed3de -t t2.micro -k my-key-pair -g my_security_group

Whenever I try to run it, I get the error message:

./my_script: line 3: ec2-describe-instances: command not found

./my_script: line 4: ec2-run-instances: command not found

These commands work when I manually enter them in command line but not when I try to make a script containing them. I have tried fiddling around with the first line that says which interpreter to use, to no avail. Any input is appreciated. Thanks

2 Answers 2

1

Sometimes using commands in a script will not work, because the script is not run in the same environment as your current login. Try including the full paths to ec2-describe-instances and ec2-run-instances. To find the full path, I believe you use the 'which' command in the command line.

Sign up to request clarification or add additional context in comments.

Comments

0

I faced the same issue. I solved the issue by exporting the home directory at the beginning of the script. In my case, I added the following.

export HOME=/root

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.