Search code examples
bashshellamazon-ec2sshgnu-screen

Shell Script - SSH using Screen


I am trying to develop a shell script / bash script with ssh and screen, using Ubuntu / Linux. Could you help me to correct what is wrong here?

#!/bin/bash
ssh -i keypair.pem -t ubuntu@ec2-address "screen -S teste"; cd 'home'; cd 'Shell'; ./'AWS - teste.sh' "

It doesn't work.


Solution

  • You fell victim to shell quoting - which is tricky when using ssh. Your command does something alike

    cd home/Shell; ./AWS - teste.sh
    

    so I would try

    ssh -i keypair.pem -t ubuntu@ec2-address screen -S teste "sh -c \"cd home/Shell; ./AWS - teste.sh\""