Skip to content

Commit

Permalink
Run double quote escaped commands in login shell (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawang35 authored Nov 7, 2018
1 parent a74bf43 commit ca5a148
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $ docker run --rm -it --env-file=.env run-on-ec2 echo \"hello world\"
Creating key pair run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Launching instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Waiting for instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce to be ready...
Running command echo "hello world" on 10.128.130.201...
Running command "echo \"hello world\"" on 10.128.130.201...
hello world
Terminating instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Deleting key pair run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Expand All @@ -53,7 +53,7 @@ $ env $(cat .env | xargs) python main.py echo \"hello world\"
Creating key pair run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Launching instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Waiting for instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce to be ready...
Running command echo "hello world" on 10.128.130.201...
Running command "echo \"hello world\"" on 10.128.130.201...
hello world
Terminating instance run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Deleting key pair run-on-ec2-eb5f9910-1635-40e1-b120-0e08b06a60ce...
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
host = instance.private_ip_address
connection = stack.enter_context(SSH(host, 'ec2-user', private_key))

print(f'Running command {command} on {host}...')
connection.run(command)
escaped_command = command.replace('"', '\\"')
print(f'Running command "{escaped_command}" on {host}...')
connection.run(f'exec $SHELL -l -c "{escaped_command}"')

0 comments on commit ca5a148

Please sign in to comment.