|
From: olingaa on 24 Jun 2008 15:10 I want to send a parameterized bash script to a cmd, something like this: cmd < cmd.sh p1 p2 Unfortunately p1 and p2 are not interpreted as parameters to cmd.sh. I tried various combinations of quoting, such as cmd < "cmd.sh p1 p2" and cmd < cmd.sh "p1 p2" as well as using here-strings: cmd <<< "cmd.sh p2 p2" and cmd <<< cmd.sh "p2 p2" none of these worked. Substituting the real command, script, and parameters I am working with looks like this with some redaction for privacy (the purpose of all this is to deploy a Java war file to a remote Tomcat server). ssh oabbott(a)stageserver < deploy.sh /var/www sitename ../build/ www.sitename.com.war deploy.sh requires three parameters.
From: Dave B on 24 Jun 2008 15:13 olingaa(a)gmail.com wrote: > I want to send a parameterized bash script to a cmd, something like > this: > > cmd < cmd.sh p1 p2 > > Unfortunately p1 and p2 are not interpreted as parameters to cmd.sh. I > tried various combinations of quoting, such as > > cmd < "cmd.sh p1 p2" > > and > > cmd < cmd.sh "p1 p2" > > as well as using here-strings: > > cmd <<< "cmd.sh p2 p2" > > and > > cmd <<< cmd.sh "p2 p2" > > none of these worked. Of course. You have to supply a file and, in the latter two cases, a string. Never a program. But whay can't you do the standard way, ie cmd.sh p1 p2 | cmd or, since you're using bash, if you absolutely want to use <, cmd < <(cmd.sh p1 p2) -- echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}'
From: olingaa on 24 Jun 2008 16:08 Thanks for your response Dave. If I understood correctly I should try pipes instead of redirection. This doesn't seem to work. If I have a file that contains "echo remote" called cmd.sh and I do ssh oabbott(a)stageserver < cmd.sh it works properly. cmd.sh | ssh oabbott(a)stageserver does not. I also tried ssh oabbott(a)BOSEXTSTAGE51 < < (deploy.sh) this gave an error. ssh oabbott(a)BOSEXTSTAGE51 << (deploy.sh) of course prompted for a here document. Your statement "You have to supply a file and, in the latter two cases, a string. Never a program." has me thinking. A bash script (program) without parameters works properly via redirection to ssh. I guess it's up to the receiving program whether to interpret the file redirected to stdin as a program but bash will not recognize the parameters as we have seen. Surely there's some way to make this work though.
From: Chris F.A. Johnson on 24 Jun 2008 16:06 On 2008-06-24, olingaa(a)gmail.com wrote: > Thanks for your response Dave. > > If I understood correctly I should try pipes instead of redirection. > This doesn't seem to work. If I have a file that contains "echo > remote" called cmd.sh and I do > > ssh oabbott(a)stageserver < cmd.sh > > it works properly. > > cmd.sh | ssh oabbott(a)stageserver > > does not. In the first instance, you are reading from the file and sending its contents as commands to ssh; in the second you are executing the command and sending its output to ssh. To do the same as the first, but using a pipe, it should be: cat cmd.sh | ssh oabbott(a)stageserver > I also tried > > ssh oabbott(a)BOSEXTSTAGE51 < < (deploy.sh) > > this gave an error. Why wouldn't it? > ssh oabbott(a)BOSEXTSTAGE51 << (deploy.sh) > > of course prompted for a here document. As it should. > Your statement "You have to supply a file and, in the latter two > cases, a string. Never a program." has me thinking. A bash script > (program) without parameters works properly via redirection to ssh. I > guess it's up to the receiving program whether to interpret the file > redirected to stdin as a program but bash will not recognize the > parameters as we have seen. The difference is in what you want to do with the file. > Surely there's some way to make this work though. To make what work? -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence
From: Dave B on 24 Jun 2008 16:21
olingaa(a)gmail.com wrote: > Thanks for your response Dave. > > If I understood correctly I should try pipes instead of redirection. > This doesn't seem to work. If I have a file that contains "echo > remote" called cmd.sh and I do > > ssh oabbott(a)stageserver < cmd.sh > > it works properly. > > cmd.sh | ssh oabbott(a)stageserver > > does not. Ok, ssh might seem a bit special in that regard, but it's actually logical. ssh takes what it reads from stdin in the local machine and sends it to the remote command's stdin, so that you can do things like tar -cvf - | ssh user(a)host "tar -xvf -" (the above line may contain some errors, but the idea should be clear). If you don't specify a command to run on the remote host, a shell is run by default. But if there is input available on stdin, that shell will read that input, assume it contains commands, and try to execute those commands. It's the same principle that makes possible things like echo "ls; cat file; time" | bash So, that's why ssh oabbott(a)stageserver < cmd.sh works and cmd.sh | ssh oabbott(a)stageserver does not. But if you understand why the first form works, then you should also realize that this cat cmd.sh | ssh oabbott(a)stageserver will work instead. > I also tried > > ssh oabbott(a)BOSEXTSTAGE51 < < (deploy.sh) > > this gave an error. > > ssh oabbott(a)BOSEXTSTAGE51 << (deploy.sh) No. It should be ssh oabbott(a)BOSEXTSTAGE51 < <(deploy.sh) (spaces *exactly* as shown). But note that, for the reasons discussed above, the *output* of deploy.sh should consist of shell commands, which are executed by the remote shell. > Your statement "You have to supply a file and, in the latter two > cases, a string. Never a program." has me thinking. A bash script > (program) without parameters works properly via redirection to ssh. I > guess it's up to the receiving program whether to interpret the file > redirected to stdin as a program but bash will not recognize the > parameters as we have seen. See above. > Surely there's some way to make this work though. Sure. -- echo 0|sed 's909=oO#3u)o19;s0#0ooo)].O0;s()(0bu}=(;s#}#.1m"?0^2{#; s)")9v2@3%"9$);so%op]t(p$e#!o;sz(z^+.z;su+ur!z"au;sxzxd?_{h)cx;:b; s/\(\(.\).\)\(\(..\)*\)\(\(.\).\)\(\(..\)*#.*\6.*\2.*\)/\5\3\1\7/; tb'|awk '{while((i+=2)<=length($1)-18)a=a substr($1,i,1);print a}' |