Reputation: 61455
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
Upvotes: 3
Views: 630
Reputation: 2853
I not fully understand your question. Other answers gave "How to run remote script?"
But i think question is Remote script has to take remote file, even I not sure about this
sshfs
if not installed .sshfs
Somewhat large procedure.
Mounting remote directory with sshfs
Upvotes: 0
Reputation: 3098
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
Upvotes: 1
Reputation: 313
If your script is in Machine A, you can't run that on Machine B without copying it over. First, copy the script over to Machine B using scp
[user@machineA]$ scp /path/to/script user@machineB:/home/user/path
Then, just run the script
[user@machineA]$ ssh user@machineB "/home/user/path/script"
This will work if you have given executable permission to the script.
OR
Try this one..
<hostA_shell_prompt>$ ssh user@hostB "ls -la"
That will prompt you for password, unless you have copied your hostA user's public key to the authorized_keys file on the home of user .ssh's directory. That will allow for passwordless authentication (if accepted as an auth method on the ssh server's configuration)
Upvotes: 0
Reputation: 325
Try this:
ssh USER_NAME@HOST_ADDRESS "BASH_SCRIPT_FILE_PATH"
You will need to provide password whenever required.
Upvotes: 1