terminal: running a command located on another machine?

Soldato
Joined
3 Dec 2002
Posts
4,034
Location
Groovin' @ the disco
Hi

Can someone the syntax to run command located on my machine on a remote machine and vice visa... running a syntax on a local machine but the command is located on a remote machine?

Assuming this is possible without copying the command locally first.

Thanks in Advance...
 
If think I sorted it..

to run a local command and send it to remote machine.
Code:
ssh command > remoteuser@remotesocket

to run a command stored on a remote machine
Code:
ssh remoteuser@remotesocket:command > localuser@localmachine

I've not tested it yet, but pretty sure at least the top one will work.. will try it when I'm back at work on Wednesday...
 
ssh user@host command

So to do a directory listing on a remote host as yourself:

ssh slinxy@somehost ls -la /some/path/here

What command are you trying to run out of interest? Some will have to be properly encapsulated in quotes etc to run, depending on how they use standard out.

Another alternative is to write a shell script and call that via the remote SSH command.
 
Hi

Thanks for the help, but that syntax would me that the command would have to be on the machine that I'm remote on to.
 
What are you trying to achieve matey?

I think you'll find the > pipes the output of the command via standard out to a file. In your first example, it'll never complete because the ssh command will try to resolve the second argument in the command as the host to act upon.

For example:
MyMachine:somepath randal$ ssh ls > randal@remotehost
sh: connect to host ls port 22: Operation timed out

In your second example:

ssh remoteuser@remotesocket:command > localuser@localmachine

remoteuser@remotesocket:command actually would translate to a host again:

MyMachine:somepath randal$ ssh randal@remotehost:/usr/bin/ls > local
ssh: connect to host remotehost:/usr/bin/ls port 22: Operation timed out

See what I mean?

The second example I gave:

ssh slinxy@somehost ls -la /some/path/here

Will do what you need, I'm sure.
 
What I'm trying to do is

A) exec a command stored only locally on the machine and not remote machine, but to affect the remote machine.

B) exec a command stored on another machine but not the stored on the machine I'm working from, but to affect the local machine.

The example you give will work if the command is on the remote machine and will affect the remote machine.

Yes I know it's far simpler to use the scp command and copy the commands back and forth, but I'm working with a rather large number of machines, and the commands only need to be exec once on the machine.

This is why I'm pipping the command to pass the command across.
 
Have you got key access set up on the machines you're trying to interact with?

If so, I'd just knock up the commands into a script and bang it out in a "for machine in 'cat machinelist.txt'" style execution with scp like you say for A. Then for B in the same for job ssh into the machine remotely and kick off another script that jumps back into the local machine again via SSH.

Difficult to say any more than that without knowing the specific commands you're running, but sounds like you've got the hang of what you need to do.
 
Back
Top Bottom