Search code examples
linuxubuntusshserverfedora

How to run a shell script over ssh with resource(.txt files) in one machine and the script in another machine?


I want to run a shell script using SSH which takes resource from other machine while the script is in some other machine, all on the same network. I don't want to copy the resource to the local machine.

Note: The shell script takes .txt file as input


Solution

  • If you have script.sh on server1 and file.txt on server2, you can connect through ssh to server1, and then do:

    [user@server1]$ ssh user@server2 "cd mydir && cat file.txt" | ./script.sh