Ian McGrath
Ian McGrath

Reputation: 1012

Executing local script/command on remote server

I have a command that I want to run on machine B from machine A. If I run the command on machine B locally, it works fine.

Here is the command:

for n in `find /data1/ -name 'ini*.ext'` ; do  echo cp $n "`dirname $n `/` basename $n 
.ext`"; done

From machine A, I issue this command

ssh user@machineB  for n in `find /data1/ -name 'ini*jsem'` ; do  echo cp $n "`dirname $n `/` basename $n .jsem`"; done

But I get error syntax error near unexpected token do

What is wrong? I think it has something to do with double quotes, single quotes, semi colon because executing command ssh user@machineB ls works fine. So not issue of authentication or something else.

Thanks

Upvotes: 0

Views: 801

Answers (1)

maialithar
maialithar

Reputation: 3123

Put your code in a script, myScript.sh and execute it, just like ls: ssh user@machineB myScript.sh

Upvotes: 1

Related Questions