I need help trying to execute a script remotely using ssh.

I'm writing a script that will run on a local machine. From that script I need to execute a script on a remote machine. The problem is that when I run the remote script using ssh, it's output is shown as if it were running locally. I need the script to run commands on the remote machine, not the local one. This is what I am doing:

ssh root@remoteServer /var/spool/asterisk/voicemail/default/script

That remote script needs to execute commands on files relative to its location on the remote machine. Maybe ssh isn't the best method to invoke this. Any help would be appreciated.

by the way... this is being done in a bash script. Thanks!

Hey there,

Interesting. your execution statement looks like it should work. You can hedge your bets by enclosing the remote command in quotes:

sh root@remoteServer "/var/spool/asterisk/voicemail/default/script"

also, to double verify, add the hostname command in there:

ssh root@remoteServer "hostname;/var/spool/asterisk/voicemail/default/script;hostname"

You should the remote host name, your output and the remote hostname again. If that works, just strip the hostname commands back out.

I'd be interested if this doesn't work. If possible, in the unfortunate event that you still experience your issue, could you send output from:

ssh -v -v -v root@remoteServer /var/spool/asterisk/voicemail/default/script

that'll give us insane debug output ;)

Best wishes,

Mike

Are you sure that it isnt working it will run the script but pull any output back to the server you are working on. Put a large sleep in the script then log on to the server that your running the script on remotely to check whether it is exeucting or not!

just redirect the output to the remote system log file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.