[英]Run ssh commande by java to launch script in ec2 instance
I have a script in amazon machine and i would run this script using ssh from netbeans. 我在亚马逊机器上有一个脚本,我会使用来自netbeans的ssh运行此脚本。 i use this code : 我使用此代码:
String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" ubuntu@ec2-53-71-22-288.eu-west-1.compute.amazonaws.com 'bash runFile.bash' -o StrictHostKeyChecking=no ";
Process p = runtime.exec(commande);
p.waitFor();
But it does not work. 但这行不通。 When i print p.getErrorStream()
I obtain: 当我打印p.getErrorStream()
我获得:
bash: writeFile.bash: command not found
When i run the commande
from bash
it works but in netbeans no ! 当我从bash
运行commande
,它可以工作,但在netbeans中,不行!
Someone can explain me why ? 有人可以解释我为什么? other solution please ? 还有其他解决方案吗?
Thanks 谢谢
Try this: 尝试这个:
String myKey="/home/local/my_key.pem";
Runtime runtime = Runtime.getRuntime();
String commande = "ssh -i "+myKey+" ubuntu@ec2-53-71-22-288.eu-west-1.compute.amazonaws.com 'bash ./runFile.bash' -o StrictHostKeyChecking=no ";
Process p = runtime.exec(commande);
p.waitFor();
(use bash ./runFile.bash
instead of bash runFile.bash
) (使用bash ./runFile.bash
代替bash runFile.bash
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.