-1
 sshpass -p "123456789" ssh -T jadams@192.168.1.85 <<'EOSSH'
    if [-d "$HOME/ajith/apache-tomcat-7.0.63/webapps/$tag_version" ] then
          sh $HOME/ajith/apache-tomcat-7.0.63/bin/shutdown.sh &&
          rm -rf  $HOME/ajith/apache-tomcat-7.0.63/webapps/$tag_version && 
          mkdir $HOME/ajith/apache-tomcat-7.0.63/webapps/$tag_version
    fi
    EOSSH

This code above is a part of the shell script which I am using

The Problem :

The problem I am facing is that I am trying to execute set of commands to deploy a webapp on a remote tomcat server and the concern of my interest is that I want to be able to execute multi-line commands using sshpass as above but I am getting error as below:

-bash: line 2: syntax error: unexpected end of file

I am searching for a working example for this use-case or any assistance relevant would be of great help.

I have tried many examples from the google search results and I am unable to do it

Ajith P
  • 21
  • 8

1 Answers1

0

I was able to solve the issue using the below mentioned code and serve my
purpose :

sshpass -p "password" ssh $server_name@$server_ip bash -c "'
    if [ -d "/home/motish/ajith/apache-tomcat-7.0.63/webapps/$tag_version" ]; then
        rm -rf /home/motish/ajith/apache-tomcat-7.0.63/webapps/$tag_version;
        mkdir /home/motish/ajith/apache-tomcat-7.0.63/webapps/$tag_version;
    fi
    else
        mkdir /home/motish/ajith/apache-tomcat-7.0.63/webapps/$tag_version;
    exit;
    '"
Jakuje
  • 24,773
  • 12
  • 69
  • 75
Ajith P
  • 21
  • 8