bash script execute commands after ssh bash script execute commands after ssh bash bash

bash script execute commands after ssh


Clean way to login through ssh and excecute a set of commands is

ssh user@ip << EOF   #some commandsEOF

here EOF acts as the delimitter for the command list

the script can be modified as

ssh -t root@IP << EOF    #switch user to deploy    su - deploy    #switch path    echo "Switching the path"    cd /var/www/deploys/bin/app/config    #run deploy script    echo "Running deploy script"    /usr/local/bin/cap -S env=prod deploy    #restart apache    sudo /bin/systemctl restart  httpd.service    bash -lEOF

will excecutes the command and closes the connection there after