0

I am trying to run a .sh script on a remote server and am getting the following error message.

Really not sure what I am doing wrong.

The command I am using is: $ssh user@remoteserver path of file to be executed/Test.sh

Which returns the error: ksh: syntax error: `(' unexpected

Any pointers would be great :)

sm4491
  • 77
  • 2
  • 9
  • **You are trying to execute a script stored at a remote site.** The shell script that you are trying to execute has syntax errors. To fix this, you need to get the script code and do the necessary modifications. – axiom Oct 31 '12 at 12:38
  • I had thought this initially. But the remote script is just a simple test script and when I ran on the remote sever it worked perfectly. Hence my confusion :( – sm4491 Oct 31 '12 at 12:46
  • It may be something that's shell specific. Maybe the script isn't written for the k shell, which is being used to run the script. – axiom Oct 31 '12 at 12:50
  • If it is a shell-specific issue, then add the name of the shell to use to the front of the command like `bash path/to/script`, or, make sure the script has an appropriate `#!` as the first line so the correct shell is automatically selected. – kbulgrien Oct 31 '12 at 13:25
  • I have included the #!/bin/ksh line at the beginning of the script – sm4491 Oct 31 '12 at 14:01
  • Again,Are you sure the script is written for the K shell? Just do some hit and trial with some other shells. ( Bash, C) – axiom Oct 31 '12 at 14:59

1 Answers1

2

If Machine A is a Windows box, you can use Plink (part of PuTTY) with the -m parameter, and it will execute the local script on the remote server.

plink root@MachineB -m local_script.sh

If Machine A is a Unix-based system, you can use:

ssh root@MachineB 'bash -s' < local_script.sh

You shouldn't have to copy the script to the remote server to run it.

Source: How to use SSH to run a shell script on a remote machine?

Community
  • 1
  • 1
Humayun
  • 976
  • 7
  • 13