I have these 2 commands that I send to my server:

- cat ./script1.sh var1 var2 | ssh my_user@my_server.com
- cat ./script2.sh var3 var4 | ssh my_user@my_server.com

This is a part of Gitlab CI, but this doesn't matter.

Is there any way to merge these 2 lines -- execute script1.sh and then script2.sh on a server? So that they'll execute within a single ssh connection.

Preferably without having to create an additional 3rd script that'll call those 2.

( echo "set var1 var2"; cat ./script1.sh; echo "set var3 var4"; cat ./script2.sh ) | ssh my_user@my_server.com 
  • vars are used -- they're command line arguments – Oddamati Sep 26 '18 at 4:07
  • The command being "cat", they will only be used if they are filenames, in which case their content will be concatenated to that of the script and the whole sent to myserver.com. – Gerard H. Pille Sep 26 '18 at 9:59
  • I don't understand – Oddamati Sep 26 '18 at 14:07
  • I know. Can you transfer the scripts to myserver.com? – Gerard H. Pille Sep 26 '18 at 14:16
  • no, they have to be a part of my project, in the repo – Oddamati Sep 26 '18 at 14:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.