0

I'm trying to connect to my server via SSH and issue some commands to it. For some reason it seems like the commands are getting cut "off".

Here is the code that does the putty connection as well as issuing the SSH commands:

./plink.exe ${USER}@${HOSTNAME} -pw ${PASS}<<SSH
cd /some/foo/bar
deploy_artifact.sh --instance development1 some_artifact.ear
APP_development1.sh restart
exit
SSH

For me it works, but on the machine of my colleague the issued SSH commands are getting cut off and thus are not interpreted correctly. For example deploy_artifact.sh is getting turned into ploy_artifact.sh (See the following the screenshot).

enter image description here

How can i prevent this? And what is causing this?

Thanks in advance for any help!

Saltuk Kezer
  • 105
  • 1
  • 7
  • Make sure you script isn't using DOS line endings. – chepner Jan 27 '22 at 15:51
  • There's something else going on as well; `APP_development1.sh` doesn't appear in the code you posted above. – chepner Jan 27 '22 at 15:53
  • @chepner Sorry, i made a mistake there. I updated the code. – Saltuk Kezer Jan 27 '22 at 15:56
  • @chepner According to notepad++ the endings are already in UNIX format (LF) – Saltuk Kezer Jan 27 '22 at 15:58
  • 2
    Does the same problem occur when the script is read from a file with the use of the `-m commands.sh` option? Also, you can try updating the ssh server on the target machine. Either the ssh server is dropping the first characters or the ssh client does not send them. – Dzienny Jan 27 '22 at 20:32
  • @Dzienny Seems to work when i read it from the file via `-m` thanks! But wat is the exact underlying issue here? It seems weird to me that this happens at all.. – Saltuk Kezer Jan 28 '22 at 15:03

1 Answers1

1

It appears the problem is with the plink and how it is used. The given example sends commands as a standard input, however I did not find in the plink manual any mention that it reads commands from the STDIN. It is better to avoid undocumented features, since they may not work correctly or the author may remove them without any notice. Instead, if you want to pass commands inline you should provide them as an argument, ie you either have to use a quoted text, or you can wrap heredoc in the "$(cat *heredoc* )" code, eg:

./plink.exe ${USER}@${HOSTNAME} -pw ${PASS} "$(cat <<SSH
cd /some/foo/bar
deploy_artifact.sh --instance development1 some_artifact.ear
APP_development1.sh restart
exit
SSH
)"

Or, you can keep the commands in a file and run the plink with the -m commands_file option.

Dzienny
  • 3,295
  • 1
  • 20
  • 30