i have a bash script on serverA, when i run the script on the server, it runs fine. the way to run the script is like this ./script "option1"
Now i am trying to call it from local laptop using ssh command, my command is as the following
ssh serverA ~/script "option1"
and i got error messages, "line 1: syntax error at ''
what could be wrong? How am i going to pass the argument in remote ssh command?
Thanks
Scott
May 21, 2010, 3:09pm
2
Hi.
You need to either escape the tilde (~), or quote the command, otherwise the ~ means the local user's home directory, not the remote one:
Before:
/Users/scott $ ssh oracle@vm_oracle_10g ~/scripts/myScript opt1 opt2 opt3
oracle@oracle's password:
ksh: line 1: /Users/scott/scripts/myScript: not found
After:
/Users/scott $ ssh oracle@vm_oracle_10g \~/scripts/myScript opt1 opt2 opt3
oracle@vm_oracle_10g's password:
Hello from myscript @ oracle@vm_oracle_10g
Options passwd were: opt1 opt2 opt3
/Users/scott $
Aside from that, be careful how you use quotes, especially if you have to mix single and double quotes
it also helps to wrap your remote command string in quotes...single-quote (') will be handled strictly verbatim, while double-quotes will allow for local variables to be used...
thanks, but in my case, the system treats the ~ as remote home dir, not the local one, since the command gets executed, but the remote system is complaining about the argument part.
line 1: syntax error at ''
Hi.
You need to either escape the tilde (~), or quote the command, otherwise the ~ means the local user's home directory, not the remote one:
Before:
/Users/scott $ ssh oracle@vm_oracle_10g ~/scripts/myScript opt1 opt2 opt3
oracle@oracle's password:
ksh: line 1: /Users/scott/scripts/myScript: not found
After:
/Users/scott $ ssh oracle@vm_oracle_10g \~/scripts/myScript opt1 opt2 opt3
oracle@vm_oracle_10g's password:
Hello from myscript @ oracle@vm_oracle_10g
Options passwd were: opt1 opt2 opt3
/Users/scott $
Scott
May 21, 2010, 3:15pm
5
Show the script you are trying to run - there is nothing I can see wrong in the command you are running (even given how it's quoted)
I'm surprised that your system knows that ~ should be treated remotely, but I take your word for it
won't work if the script is only on the local machine and the SQL client is on the remote...unless local and remote are the same machine, of course...
Scott
May 21, 2010, 3:18pm
7
Or have the same script in both home directories
Is the command you show us the actual command you are running? i.e. if your command contains variables, and it's not quoted, then.....
ah, thanks everybody, i figured it out. using both single and double quotes solves the problem.
ssh ServerA "~/script '$option' '$optionb' '$optionc'"
and scottn, i am using ubuntu, and i guess it is smart enough to regard ~ as remote home dir.
Thanks everyone for the quick answers.