passing arguments in remote ssh command?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing arguments in remote ssh command?
# 1  
Old 05-21-2010
passing arguments in remote ssh command?

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

Code:
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

Last edited by Scott; 05-21-2010 at 04:14 PM.. Reason: Code tags
# 2  
Old 05-21-2010
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:
Code:
/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:
Code:
/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 Smilie
# 3  
Old 05-21-2010
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...
# 4  
Old 05-21-2010
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 ''


Quote:
Originally Posted by scottn
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:
Code:
/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:
Code:
/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 $

# 5  
Old 05-21-2010
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 Smilie
# 6  
Old 05-21-2010
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... :P
# 7  
Old 05-21-2010
Quote:
Originally Posted by curleb
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... :P
Or have the same script in both home directories Smilie

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.....

Last edited by Scott; 05-21-2010 at 04:25 PM.. Reason: Clarification on a question
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete line from remote file over ssh passing variable

I have a variable called $a1 which maps to something like "http://servername proxy1 count http" and a lots of entries in a file on remote server. If I have the following in my .sh script: sed -i "\%$a1%d" mylog.txtthe line is deleted from mylog.txt. Great. I'm trying now to remvoe this from a... (3 Replies)
Discussion started by: say170
3 Replies

2. Shell Programming and Scripting

Passing password with SSH command

Hi Experts, I have specific requirement where I want to pass the password with the ssh username@hostname command . I dont want to use RSA public and private keys also. Because that will be on production server and no one wants to give access like that. Second thing it is production... (14 Replies)
Discussion started by: sharsour
14 Replies

3. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. UNIX for Dummies Questions & Answers

passing command arguments from a file?

Hi Im trying to run zip shell command from an Oracle job, but this has limitations. This should take a few of explanaition,.. Oracle allows me to execute a command and then I can set up a fixed number of arguments. Ex: (summarizing in something like..): JOB DEFINITION job_name: test... (4 Replies)
Discussion started by: vegatripy
4 Replies

5. Shell Programming and Scripting

Passing arguments from a bash shell script to a command

I'm pretty new to bash scripting and I've found myself writing things like this (and the same with even more nesting): if $CATEGORIES; then if $LABEL_SLOTS; then $pyth "$wd/texify_grammar.py" "$input" "$texfile" "--label-slots" "--categories" "$CATEGORY_LIST" ... (9 Replies)
Discussion started by: burbly
9 Replies

6. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

7. Shell Programming and Scripting

passing arguments to unix command or script inside tclsh

hi everobody kindly consider the following in tclsh I understand that we can do the following %exec UnixCmd arg1 arg2 but if I assinged the arguments to a list insde tclsh how can I use them back i.e %set ArgList %exec UnixCmd %exec Unixcmd $list %exec all the... (1 Reply)
Discussion started by: Blue_shadow
1 Replies

8. Shell Programming and Scripting

Passing SSH Command Parameters

Hi, I wan to pass arguments to remote script in Unix . For that I'm using ssh PFB the code I'm using: ssh -t -l osdac 10.81.33.51 "cd /appl/OSD/LOGS/flstr010/test.sh "$1" "$2"" Problem is I'm not able to pass second argument . Can anyone plz help me in resolving this. (5 Replies)
Discussion started by: suchitasaner27
5 Replies

9. AIX

Passing a command over SSH

I'm trying to run a command over ssh to AIX 5.2, something like: ssh machine ls but it just hangs. I can ssh into the machine and run a command, but can't pass it like above. Is there a security setting that disables this by default? If so, how do I change it? Thanks! (8 Replies)
Discussion started by: hansnueski
8 Replies

10. Solaris

Passing SSH Command Parameters

On Solaris 5.9, is there any way to pass parameter(s), via SSH, to a command defined in the remote host's authorized_keys file? We have a menu that uses SSH to control some apps on our various hosts. I've been tasked with enhancing it and making it more secure. So far, the local host menu... (2 Replies)
Discussion started by: PabloCruise77
2 Replies
Login or Register to Ask a Question