LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Running a shell script remotely via 'ssh <hostname> <command>' (https://www.linuxquestions.org/questions/linux-general-1/running-a-shell-script-remotely-via-ssh-hostname-command-370951/)

davee 10-08-2005 12:35 PM

Running a shell script remotely via 'ssh <hostname> <command>'
 
If I use the above format to run a shell script, it runs the script locally.

How can I get it to run on the remote box? It requires binaries (i.e. sqlplus, sqlloader) that are not on my local box. I only want the ssh command to kick it off remotely...

Dave

nixcraft 10-08-2005 01:30 PM

You need sqlplus, sqlloader etc on remote box, then you can use it. SSH cannot do such work

davee 10-08-2005 02:03 PM

That's what I mean - the script, sqlloader, sqlplus, etc, etc are all on the remote box. I only want to start the thing running via ssh from my local box.

Dave

Quigi 10-08-2005 02:59 PM

Then you're on the right track. My experience with ssh says it would run remotely. So make sure to
  • omit the single quotes around the command line (but it wouldn't run locally with them anyway),
  • replace <hostname> with the name of the host,
  • replace <command> with the path to the script.
Well probably you did that. What makes you think it ran locally? I mean, what output did you expect? What did you get?

You could try with a simple known command first. E.g., "hostname" or "uname -a" -- without the double quotes. Like this,
Code:

ssh other-host uname -a
From the output it should be obvious where it ran (if the two machine have different names). If that still runs locally, check if your <hostname> gets resolved to the correct IP address. If you just run 'ssh <hostname>' and give no command, does that successfully give a shell on the remote host?

davee 10-09-2005 02:38 AM

Ah hah! thanks for that -

Turns out that the environment for sql is set from the .profile - this wasn't being processed before the command was run via ssh.

Running:

ssh hostname '. /home/user/.profile; command.sh'

gave the right result.

Thanks for putting me on the right track.

Dave


All times are GMT -5. The time now is 03:55 AM.