通过 ssh 命令从另一个 shell 文件传递 shell 文件中 SQL 语句的参数
我将命令行参数传递给 shell 文件,即 allocateRole.sh,其中包含一个 SQL 命令,该命令将使用这些参数,如下所示
ssh -o StrictHostKeyChecking=no -T $key < /oracle/oracle_user/makhshif/./assignRole.sh name open_mode >> /oracle/oracle_user/dftest.txt
这给了我错误,并且不接受 name 和 open_mode< 的参数/strong> 并给出错误,但如果我在 ssh 命令之外执行语句,例如:
/oracle/oracle_user/makhshif/./assignRole.sh name open_mode
这运行良好
ssh 命令有什么问题以及我应该如何调整这些参数以便 shell 脚本 allocateRole.sh 可以接受这些参数
I am passing command line arguments to a shell file i.e assignRole.sh which contains an SQL command which will use these arguments like below
ssh -o StrictHostKeyChecking=no -T $key < /oracle/oracle_user/makhshif/./assignRole.sh name open_mode >> /oracle/oracle_user/dftest.txt
This gives me error and does not accept arguments of name and open_mode and gives error, but if I execute the statement outside of ssh command like:
/oracle/oracle_user/makhshif/./assignRole.sh name open_mode
This runs fine
What is the problem with ssh command and how should I adjust these parameters so these can be accepted for the shell script assignRole.sh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此命令将该文件的内容发送到标准输入。显然它无法处理您尚未发送到远程计算机的变量。只需预处理您的脚本或在远程计算机上创建一个脚本并使用参数调用它
尽管传递这样的变量更容易:
例如我在所有集群节点上执行更新脚本的函数:
然后我像这样使用它:
此命令执行 < code>script06.sh 在 3 台服务器上(zoo1、zoo2、zoo3)
This commands sends a content of that file to stdin. So obviously it can't process variables that you haven't send to remote machine. Just preprocess your script or create a script on remote machine and call it with arguments
Though it's even easier to pass variables like this:
For example my function for executing update scripts on all cluster nodes:
Then I use it like this:
This command executes
script06.sh
on 3 servers (zoo1,zoo2,zoo3)正如 Sayan 所说,使用
<
会重定向本地运行assignRole.sh
脚本的输出,但您希望使用参数在远程主机上执行该脚本。将整个命令作为最后一个参数传递给
ssh
,用引号括起来:或分成多行以提高可读性:
As Sayan said, using
<
redirects the output of running theassignRole.sh
script locally, but you want to execute that script on the remote host, with the arguments.Pass the whole command as the final argument to
ssh
, in quotes:or split into multiple lines for readability: