How to do file transfer inside ssh command line?

Rajesh

I have to transfer a file from server A to B and then needs to trigger a script at Server B. Server B is a Load balance server which will redirect you either Server B1 or B2 that we dont know.

I have achieved this as below.

sftp user@Server
put file
exit

then executing the below code to trigger the target script

ssh user@Server "script.sh"

But the problem here is as I said it is a load balance server, Sometimes I am putting file in one server and the script get triggers in another server. How to overcome this problem?

I am thinking some solutions like below

ssh user@server "Command for sftp; sh script.sh"

(i.e) in the same server call if I put and triggers it will not give me the above mentioned problem. How can I do sftp inside ssh connection? Otherwise any other suggestions?

Petesh

if you're just copying a file up and then executing a script, and it can't happen as two separate commands you can do:

gzip -c srcfile | ssh user@remote 'gunzip -c >destfile; script.sh'

This gzips srcfile, sends it through ssh to the remote end, gunzips it on that side, then executes script.sh.

If you want more than one file, you can use tar rather than gzip:

tar czf - <srcfiles> | ssh user@remote 'tar xzf -; script.sh'

if you want to get the results back from the remote end and they're files, you can just replicate the tar after the script…

tar czf - <srcfiles> | ssh user@remote 'tar xzf -; script.sh; tar czf - <remotedatafiles>' | tar xzf -

i.e. create a new pipe from ssh back to the local environment. This only works if script.sh doesn't generate any output. If it generates output, you have to redirect it, for example to /dev/null in order to prevent it messing up the tar:

tar czf - <srcfiles> | ssh user@remote 'tar xzf -; script.sh >/dev/null; tar czf - <remotedatafiles>' | tar xzf -

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I transfer (to a usb drive) or read a .odt file in the command-line?

From Dev

How do I batch rename a specific file inside multiple zip archives via the command line?

From Dev

How to download a file from the command line? via ssh?

From Dev

How to upload a file from the command line with FTP or SSH?

From Dev

How do ssh remote command line arguments get parsed

From Dev

How to replace a word inside a .DOCX file using Linux command line?

From Dev

Command line command to copy a file inside the subfolders

From Dev

FTP transfer server to server using SSH/command line

From Dev

How do I loop over each line inside a file with ansible?

From Dev

How to transfer a file in an "indirect" ssh connection?

From Java

How do I import an SQL file using the command line in MySQL?

From Dev

How do I open a file with Chrome from the command line?

From Dev

How do I deploy a file to Artifactory using the command line?

From Dev

How do I stop a batch file retaining control of the command line

From Dev

How do I install a .deb file via the command line?

From Dev

How do I install a .deb file via the command line?

From Dev

How do I search a PDF file from command line?

From Dev

How do I get a specific line of a file using 'cat' command?

From Dev

How do you write to a file within the command line?

From Dev

How do you create an empty file from the command line in Windows

From Dev

How do I send a file with FileZilla from the command line?

From Dev

How do I run .c file from the command line

From Dev

How do I change file headers from the command line?

From Dev

How do I find the biggest file in a folder and subfolders on the command line?

From Dev

How do I search a txt file for names from command line or interactive command line

From Dev

how to correctly write command inside commands (ssh)?

From Dev

What does the command-line option "-A" in the ssh command do?

From Dev

How to use environment modules in a ssh command line?

From Dev

How do terminal size changes get sent to command line applications though ssh or telnet?

Related Related

  1. 1

    How do I transfer (to a usb drive) or read a .odt file in the command-line?

  2. 2

    How do I batch rename a specific file inside multiple zip archives via the command line?

  3. 3

    How to download a file from the command line? via ssh?

  4. 4

    How to upload a file from the command line with FTP or SSH?

  5. 5

    How do ssh remote command line arguments get parsed

  6. 6

    How to replace a word inside a .DOCX file using Linux command line?

  7. 7

    Command line command to copy a file inside the subfolders

  8. 8

    FTP transfer server to server using SSH/command line

  9. 9

    How do I loop over each line inside a file with ansible?

  10. 10

    How to transfer a file in an "indirect" ssh connection?

  11. 11

    How do I import an SQL file using the command line in MySQL?

  12. 12

    How do I open a file with Chrome from the command line?

  13. 13

    How do I deploy a file to Artifactory using the command line?

  14. 14

    How do I stop a batch file retaining control of the command line

  15. 15

    How do I install a .deb file via the command line?

  16. 16

    How do I install a .deb file via the command line?

  17. 17

    How do I search a PDF file from command line?

  18. 18

    How do I get a specific line of a file using 'cat' command?

  19. 19

    How do you write to a file within the command line?

  20. 20

    How do you create an empty file from the command line in Windows

  21. 21

    How do I send a file with FileZilla from the command line?

  22. 22

    How do I run .c file from the command line

  23. 23

    How do I change file headers from the command line?

  24. 24

    How do I find the biggest file in a folder and subfolders on the command line?

  25. 25

    How do I search a txt file for names from command line or interactive command line

  26. 26

    how to correctly write command inside commands (ssh)?

  27. 27

    What does the command-line option "-A" in the ssh command do?

  28. 28

    How to use environment modules in a ssh command line?

  29. 29

    How do terminal size changes get sent to command line applications though ssh or telnet?

HotTag

Archive