1

I connect to a lot of Linux servers with ssh and run a health check script on each, wanted to save myself 2 secs per server when doing so. So instead of normally creating the script file:

cat > test.sh
+
right-click paste(whole script file -copied from notepad)
+
ctrl+c

I right click paste: here doc with whole script(copied form notepad):

cat <<'EOF' > test.sh
#!/bin/bash
commands..
commands..
EOF

Aprox 50% times script inside gets corrupted when pasted like this. Corruption occurs on random line/lines(part of line is missing, some characters are missing etc.) which results in syntax errors when script is run, other 50% times script is pasted OK and can be run OK.

Problem is definitely not in the script itself. When it is copied cat > filename way, it works 100%. Notepad where the text is copied from uses UNIX - LF EOL conv. but this also happens when switched to windows CRLF type. Script has no tabs inside, just whitespaces also limitString has no leading whitespace before itself

Script is 430 lines long, could this be a problem? I have been using same syntax for some time in some other bash scripts or directly in terminal but never experienced such behavior.

Anyone has ideas what might be causing this? Or possible workaround?

  • Can't think what's causing it, but is there any reason not to make the `heredoc` part of the initial `ssh` command rather than pasting it onto the remote machine? ```ssh user@machine << 'EOF' ... EOF``` – IBam Jan 30 '18 at 13:11
  • Actually, what kernel are the remote machines running? http://lists.gnu.org/archive/html/bug-readline/2013-07/msg00006.html could be related – IBam Jan 30 '18 at 13:11
  • it is mostly RHEL7 and RHEL6 (different releases) this bug sound very similar. Making heredoc part of initial ssh might solve this. There is no reason preventing this approach. I will update once i do some tests with initial ssh. – Martin Fejfár Jan 30 '18 at 14:03
  • How is this a StackOverflow question? Problems with copy-and-paste not working right in your terminal are end-user errors, appropriate for [unix.se] or [SuperUser](https://superuser.com/). It'd be a development question suited for SO if you were the person writing the terminal, but not if you're the person using it. – Charles Duffy Jan 30 '18 at 16:24
  • ...that said, there are *definitely* better ways to copy a file to a remote server, if that's your goal (perhaps you should ask about that, rather than about an issue that came up with the interim attempt). – Charles Duffy Jan 30 '18 at 16:26
  • Yes, indeed you are right, this might be wrong place for this question. Thanks for pointing that out – Martin Fejfár Feb 02 '18 at 13:31

1 Answers1

0

Try as suggested here

ssh remoteuser@ip.address.of.server 'bash -s' < scriptfile.sh
LMC
  • 10,453
  • 2
  • 27
  • 52
  • If this addresses the OP's intended question, that question should be closed as a duplicate of [How to use ssh to run a shell script on a remote machine?](https://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-a-shell-script-on-a-remote-machine) – Charles Duffy Jan 30 '18 at 16:27
  • Thank you for suggestion i will use some different approach to my issue. Yes i think this can be closed as duplicate. – Martin Fejfár Feb 02 '18 at 13:32