【问题标题】:jsch and running sudo from a particular directoryjsch 并从特定目录运行 sudo
【发布时间】:2013-04-17 18:43:12
【问题描述】:

我已连接到远程 ubuntu 服务器。在连接时,我想执行下面的 shell 命令

String command = "cd "to some directory" ; 
sudo ./i3lsdd"; 
// want to move to a directory and execute sudo ./i3lsdd command.

我使用了下面的代码,但它给出了这个错误:

"sudo: no tty present and no askpass program specified 抱歉,试试 再次。”

非常感谢任何帮助。

【问题讨论】:

    标签: java linux


    【解决方案1】:

    在主目录的 .sh 文件中保留命令“sudo ./i3lsdd”。

    使用

    获取主目录路径
    String path = channelSftp.pwd();
    

    编写如下命令

    String command = "sudo -S " + path + "/scriptname.sh"; 
    

    使用以下代码提供密码

    out1.write((sudo_pass + "\n").getBytes()); 
    out1.flush();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      • 2015-08-31
      • 2020-04-30
      • 2017-09-14
      • 2012-08-11
      • 2018-02-05
      相关资源
      最近更新 更多