[英]how to do ssh from the bash script
I have tried to run the following command from command line and it works perfect as expected我试图从命令行运行以下命令,它按预期完美运行
ssh someIP "java -jar /path/program.jar "someIP""
but when i wrote in the bash script as following:但是当我在 bash 脚本中这样写时:
ssh $f1 \"java -jar /path/program.jar \"$f1\"\" ;
where $f1 is the ip address.其中 $f1 是 IP 地址。 it does not work and gives me the error:
它不起作用并给我错误:
bash: java -jar /path/program.jar someIP: No such file or directory
bash: java -jar /path/program.jar someIP: 没有那个文件或目录
I tried to echo the ssh command and it is correct and i just copied the echoed command and pasted on the command prompt and it has worked.我试图回显 ssh 命令,它是正确的,我只是复制了回显的命令并粘贴到命令提示符上,它已经工作了。 So I am now confuse, what is wrong in the bash script that I am missing
所以我现在很困惑,我缺少的 bash 脚本有什么问题
You can try not to escape.你可以尽量不要逃避。
#!/bin/bash
ssh $1 "java -jar program.jar "$1""
You could try EOF.你可以试试EOF。
ssh $1 << EOF
#commands here
EOF
After the commands are done the connection is severed.命令完成后,连接被切断。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.