Wednesday, February 1, 2017

EOF use to execute multiple commands on remote server

You can run the Linux commands on the remote machine using the loop in the bash script.

If you want to run a multiple commands on the remote server than you can use the EOF which opens a buffer/file in which you can enter the multiple commands which you want to execute on the remote machine. Once done entering the command than you can again use the EOF to end entering the command and in a way it closes the buffer/file.

EOF allows you to redirect the output of the EOF to some command. Like in our case we are redirecting the output to the sudo -i to execute those commands using the root user.

 for i in `cat file.txt`;do echo "###$i####";ssh -t -i key.pem -p 22 ec2-user@$i 'sudo -i << \EOF   
 export https_proxy=http://proxy.example.com:3128;export http_proxy=http://proxy.example.com:3128;  
 yum install sendmail -y  
 EOF'; done  


Post a Comment