LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash - start remote script from local script? (https://www.linuxquestions.org/questions/programming-9/bash-start-remote-script-from-local-script-633166/)

babag 04-04-2008 10:22 PM

bash - start remote script from local script?
 
i have a bash script that runs on my local computer
and moves files from one remote computer to another
for processing. the processing computer executes its
processing via its own bash script.

is there a way i can have my local computer's script
tell the processing computer to run its own processing
script? currently, i'm waiting for the local script to
complete and then going over to the processing computer
to start its script. would be a lot easier if i could
put it all into the local script. just have no idea
how.

thanks,
BabaG

Neuzen 04-04-2008 11:05 PM

using SSH
 
Hi babag,
My suggestion is to use ssh to send commands to your remote computer.
on your script you can add:

ssh <remote computer's IP address> <command>

I hope that I help a little bit.

B.T.W
You can even remove the request to enter password by adding your RSA key
to the remote computers authorized keys list.

Regards,

babag 04-05-2008 11:50 AM

great suggestion neuzen. one question: if, as you suggest,
i issue a command via ssh, and that command is to run a
script on the remote computer, when does my local script
continue? after the ssh command is issued? after the remote
script starts? after the remote script ends? if it's the
last of these possibilities i'd have a problem since the
remote script will take hours to run and i'm ready to move
on as soon as it's been told to start running.

thanks,
BabaG

babag 04-05-2008 09:54 PM

oops. just hit a snag. got ssh working and can start a remote
script from my local script (yay!). problem is, remote script
has to be in remote's home directory, not subdirectory. i
need to send both a cd command, as well as the command to
start the script. so far, all i know how to do is the login
and send one command. i have this to run the script if it's
in the home directory:

ssh useracct@remotecomputer ./script_to_run.sh

what i need to be able to do is something like:

ssh useracct@remotecomputer cd Documents/Scripts ./script_to_run.sh

how do i send more than just the one command?

thanks,
BabaG

Neuzen 04-05-2008 11:54 PM

no problem.
 
Hi BabaG,
This is no problem,
You just include the script path, for example lets say you want to run command from /sbin/MyCommand you should type:

ssh <remote computer IP> /sbin/MyCommand.

Or you can just include your command path to PATH (env. variable) on your remote computer.

Regards,

jschiwal 04-06-2008 12:00 AM

Including the full path to a command (or fully defining the environment) is best practice for scripts anyway. A change in the environment won't run the wrong command.

babag 04-06-2008 12:35 AM

thanks neuzen and jschiwal. i had one of those 'DOH!' moments
driving home after posting the question when i realized just
what you're saying. i'd still be very interested, though, to
know about issuing multiple commands through an ssh script.

thanks again,
BabaG

babag 04-06-2008 05:46 PM

just noticed this:

ssh <remote computer IP> /sbin/MyCommand

has no "." before the command. running the command
without the path included i had:

ssh useracct@remotecomputer ./script_to_run.sh

is there no "."? or should it be:

ssh <remote computer IP> ./sbin/MyCommand

{EDIT}
ok. no "."
it works now.

thanks,
BabaG


All times are GMT -5. The time now is 07:35 PM.