From: rpg.jhansi on 19 Nov 2008 04:43 Hi, I have following script, one of the argument to this scipt is shell variable which actually contains the script command. $echo $script cd /usr/local/site/pvr/config; grep -i jdbc ofoto.properties mod.ofoto.properties $./ssh_prop.exp ptatinen ussa-flab021.stage.ofoto.com rockon(a)23 $ {script} spawn ssh ptatinen(a)ussa-flab021.stage.ofoto.com cd {/usr/local/site/ pvr/config;} grep -i jdbc ofoto.properties mod.ofoto.properties Password: bash: -c: line 0: syntax error near unexpected token `}' bash: -c: line 0: `cd {/usr/local/site/pvr/config;} grep -i jdbc ofoto.properties mod.ofoto.properties' bash: -c: line 0: syntax error near unexpected token `} sh: Syntax error: EOF in backquote substitution child process exited abnormally while executing "system "echo '$output' > search.txt"" (file "./ssh_prop.exp" line 35) In summary, it's interpeating the $shell variable incorrectly. Any help please to resolve this./
From: Cameron Laird on 19 Nov 2008 13:09 In article <5aad1dcb-f885-4812-8957-b3f15d7c5902(a)q26g2000prq.googlegroups.com>, <rpg.jhansi(a)gmail.com> wrote: >Hi, > >I have following script, one of the argument to this scipt is shell >variable which actually contains the script command. > >$echo $script >cd /usr/local/site/pvr/config; grep -i jdbc ofoto.properties >mod.ofoto.properties > >$./ssh_prop.exp ptatinen ussa-flab021.stage.ofoto.com rockon(a)23 $ >{script} > >spawn ssh ptatinen(a)ussa-flab021.stage.ofoto.com cd {/usr/local/site/ >pvr/config;} grep -i jdbc ofoto.properties mod.ofoto.properties >Password: >bash: -c: line 0: syntax error near unexpected token `}' >bash: -c: line 0: `cd {/usr/local/site/pvr/config;} grep -i jdbc >ofoto.properties mod.ofoto.properties' > >bash: -c: line 0: syntax error near unexpected token `} >sh: Syntax error: EOF in backquote substitution >child process exited abnormally > while executing >"system "echo '$output' > search.txt"" > (file "./ssh_prop.exp" line 35) > >In summary, it's interpeating the $shell variable incorrectly. > >Any help please to resolve this./ > > [system] evaluates a command with /bin/sh <URL: http://docs.activestate.com/activetcl/8.5/expect4win/expect.html#exp_system > and does NOT respect $SHELL. I can imagine it having been defined differently--but it wasn't. Was that your question?
From: Glenn Jackman on 19 Nov 2008 20:15 At 2008-11-19 04:43AM, "rpg.jhansi(a)gmail.com" wrote: > Hi, > > I have following script, one of the argument to this scipt is shell > variable which actually contains the script command. > > $echo $script > cd /usr/local/site/pvr/config; grep -i jdbc ofoto.properties > mod.ofoto.properties > > $./ssh_prop.exp ptatinen ussa-flab021.stage.ofoto.com rockon(a)23 ${script} Perhaps you meant to say: $./ssh_prop.exp ptatinen ussa-flab021.stage.ofoto.com rockon(a)23 "$script" > spawn ssh ptatinen(a)ussa-flab021.stage.ofoto.com cd {/usr/local/site/ > pvr/config;} grep -i jdbc ofoto.properties mod.ofoto.properties In your expect script, you appear to be treating the list $argv as a string. -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous
From: rpg.jhansi on 20 Nov 2008 00:45 Apologies for short information. Here is the scenario which is not working for me. 1. I have a shell script in BASH, which constructs a shell variable containing some command e.g. var=cd /usr/local/home/user/server/config; grep -i propname properties.file 2. I called an expect script from this shell script. The purpose of this expect script is to SSH to remote server and execute the command mentioned in the variable $var. 3. In the Bash Script, I call the expect script in following way expect.exp $host_name $user $password $var 4. In the Expect script, I read these command line arguments in following way: set host_name [lrange $argv 0 0] set user [lrange $argv 1 1] set password [lrange $argv 2 2] set var [lrange $argv 3 end] 5. I spawn the ssh in expect in the following way: spawn ssh $user@$host_name $var Observations: It looks like that while interpreting the variable $var (which contains the shell commands), it's appending the curly braces and hence bash is not able to understand it. Here is the error message I am getting: spawn ssh ptatinen(a)essa-rtapp001.stage.ofoto.com {cd /usr/local/site/ pvr/config/; grep -i jdbc ofoto.properties} Password: bash: {cd: command not found grep: ofoto.properties}: No such file or directory expect: spawn id exp7 not open while executing "expect "*"" (file "./ssh_prop.exp" line 36) NOTE: Please see it's appending the curly braches while interpreating the variable $var. Due to this bash is not able to understand and throwing error. Please help in this regard.
From: Bryan Oakley on 20 Nov 2008 10:27 On Nov 19, 11:45 pm, rpg.jha...(a)gmail.com wrote: > Apologies for short information. > Here is the scenario which is not working for me. > > 1. I have a shell script in BASH, which constructs a shell variable > containing some command e.g. > var=cd /usr/local/home/user/server/config; grep -i propname > properties.file > > 2. I called an expect script from this shell script. The purpose of > this expect script is to SSH to remote server and execute the command > mentioned in the variable $var. > > 3. In the Bash Script, I call the expect script in following way > > expect.exp $host_name $user $password $var > > 4. In the Expect script, I read these command line arguments in > following way: > > set host_name [lrange $argv 0 0] > set user [lrange $argv 1 1] > set password [lrange $argv 2 2] > set var [lrange $argv 3 end] > > 5. I spawn the ssh in expect in the following way: > > spawn ssh $user@$host_name $var > > Observations: It looks like that while interpreting the variable $var > (which contains the shell commands), it's appending the curly braces > and hence bash is not able to understand it. Here is the error message > I am getting: > > spawn ssh ptati...(a)essa-rtapp001.stage.ofoto.com {cd /usr/local/site/ > pvr/config/; grep -i jdbc ofoto.properties} > Password: > bash: {cd: command not found > grep: ofoto.properties}: No such file or directory > expect: spawn id exp7 not open > while executing > "expect "*"" > (file "./ssh_prop.exp" line 36) > > NOTE: Please see it's appending the curly braches while interpreating > the variable $var. Due to this bash is not able to understand and > throwing error. > > Please help in this regard. Let's see if I can explain this clearly. It can be confusing. Instead of this: set host_name [lrange $argv 0 0] set user [lrange $argv 1 1] set password [lrange $argv 2 2] set var [lrange $argv 3 end] You should be doing this: set host_name [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] set var [lindex $argv 3] Notice the use of lindex rather than lrange. The reason is, using lrange means that host_name, user, password and var will be lists instead of scalers. You are getting lucky with the first three because the string representation of lists with simple values is often the same as the values separated with spaces (read: [list foo bar] == "foo bar"). As you have discovered, however, this is not always the case. For example, notice that [list "foo bar"] is not the same as "foo bar". This is what you are experiencing with $var -- the string representation of the list inside of var is not the same as the string that is the first and only element in the list. In your code, the variable var is a list that has as it's only element the string "cd ...; grep ..." which is functionally identical to the following: set var {{cd ...; grep ...}} When you use $var as a string (which is how ssh sees it), tcl must convert the list to a string. When it does this it tries to preserver the "listness" of the data so it will add curly braces or backslashes as necessary. That is why the ssh command you spawn is seeing these curly braces. The solution is straight-forward, boiling down to "don't pass a list as an argument to the spawn command". Either don't make your variables lists to begin with (use lindex rather than lrange), or explicitly convert the list to a string in a way that gets you what you want (for example, [join $var " "])
|
Pages: 1 Prev: working with oracle clob Next: http::geturl Illegal characters in URL path |