2

I have an ec2 instance"abc1"(ubuntu) and I create image from abc1. Then,I launch a new instance "abc2" from abc1 image. I want abc2 to run the script when it will be launched.
So,I write the text in userdata:

#!/bin/bash
cd ~/env/xxx/bin/
source activate
python3.6 ~/env/xxx/source/test.py

I manually use these commands,it's valid.However,it doesn't work when using userdata automatically. Does anyone know how to adjust my settings? Thanks a lot.

1 Answer 1

2

My guess is that you are ssh'ing into the ec2 instance as a different user than the instance is running it at, so the HOME directory (~) is not the same when run manually vs run with cloudinit.

Try writing the script using absolute paths, not relative paths.

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

1 Comment

Thanks a lot.I have tried to write the script using absolute path(/home/ubuntu/env/xxx/bin/),but it shows /root/env/xxx/bin/ "/home/ubuntu" is exchanged to "/root/" that means I only can excute the program under the root.

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.