'Connection to EC2 instance closed

If I connect to an AWS EC2 instance with ssh and execute the corresponding statement, the connection is disconnected. It doesn't even seem to run properly for some reason.

I run at local:

ssh -o ServerAliveInterval=300 -i $AWS_KEY -t ubuntu@$INSTANCE_DNS 'cd /home/ubuntu/HW /;sudo bash ./settings.sh'

ssh -o ServerAliveInterval=300 -i $AWS_KEY -t ubuntu@$INSTANCE_DNS 'cd /home/ubuntu/HW /;sudo bash ./run_all.sh'
# run.sh
chmod +x run_dstat.sh
chmod +x run_nvidia.sh
chmod +x run_workload.sh
nohup ./run_dstat.sh >nohup.out & nohup ./run_nvidia.sh >nohup2.out & nohup ./run_workload.sh >nohup3.out & 
# setting.sh
pip3 install tensorflow==2.7.0
sudo apt update
sudo apt install dstat
chmod +x run_all.sh

output

Successfully installed  ~~~~
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.3.1; however, version 22.0.3 is available.
You should consider upgrading via the '/usr/bin/python3.7 -m pip install --upgrade pip' command.
rm: cannot remove '/var/cache/apt/archives/lock': No such file or directory
Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease                                                                    
Hit:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease                                                                  
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease                                                                                
Get:5 https://nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64  InRelease [1484 B]                                                  
Get:6 https://nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/amd64  InRelease [1481 B]
Get:7 https://nvidia.github.io/nvidia-docker/ubuntu18.04/amd64  InRelease [1474 B] 
Hit:8 https://fsx-lustre-client-repo.s3.amazonaws.com/ubuntu bionic InRelease      
Fetched 4439 B in 1s (6862 B/s)                   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
55 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python-pip-whl python3-keyring python3-keyrings.alt python3-secretstorage python3-wheel python3-xdg
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  dstat
0 upgraded, 1 newly installed, 0 to remove and 55 not upgraded.
Need to get 52.1 kB of archives.
After this operation, 443 kB of additional disk space will be used.
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu bionic/universe amd64 dstat all 0.7.3-1 [52.1 kB]
Fetched 52.1 kB in 0s (0 B/s)    
Selecting previously unselected package dstat.
(Reading database ... 142222 files and directories currently installed.)
Preparing to unpack .../archives/dstat_0.7.3-1_all.deb ...
Unpacking dstat (0.7.3-1) ...
Setting up dstat (0.7.3-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Connection to ec2-34-228-71-59.compute-1.amazonaws.com closed.
start experiment
Connection to ec2-34-228-71-59.compute-1.amazonaws.com closed.

The funny thing is, if you directly connect to the instance and run it, it runs normally. Why doesn't it work only when using ssh?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source