通过.bat中的Plink脚本表现不同

时间:2016-07-11 18:04:05

标签: batch-file ubuntu ssh putty plink

我的Windows计算机上有一个.bat文件。此.bat文件使用plink.exe连接到Ubuntu计算机并执行.sh脚本。但是,根据Plink的使用方式,我在脚本上会有不同的行为:

  1. 直接登录Ubuntu(亲自) - 脚本成功

  2. 通过Bitvise客户端
  3. ssh - 脚本成功

  4. ssh通过Plink(通过调用plink.exe)并从交互式shell调用脚本(它是Windows cmd.exe中的Ubuntu shell) - 脚本成功

  5. ssh通过.bat然后调用Plink - 脚本失败

  6. 脚本失败,显示消息:

      加载共享库时出现

    错误:libCint.so:无法打开共享对象文件:没有这样的文件或目录

    其他帖子似乎是指libCint.so的安装/权限问题,但我知道情况并非如此,因为脚本在其他实例中正常工作,如上所示。

    以下是plink.exe文件中的.bat行:

    plink.exe !plink_ssh_details! myscript
    

    通过.bat文件以这种方式调用上述脚本失败;再次注意,当直接从Ubuntu调用或者我通过cmd.exe(使用plink.exe)或Bitvise客户端直接进入Ubuntu时,它会成功。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

在其他情况下,您正在使用互动会话。

虽然默认情况下Plink使用非交互式会话,但在命令行中指定命令时。

您的脚本可能依赖于某些特定设置的环境变量(如PATH)。

很可能只为交互式会话设置变量。可能是因为它们是在仅为交互式会话执行(源)的启动脚本中修改的。

解决方案是:

一些更加模糊的SSH服务器在" exec" channel用于执行命令。请参阅Executing command on Plink command line fails with "not found"

答案 1 :(得分:0)

I had to hack a solution to work around this problem. Adding a "-i" option at the header of the bash script I was invoking from my .bat file did the trick:

#!/bin/bash -i

Note some warn of unwanted side effects (no mention of specifics tho...) when using this option. But calling this now interactive script from a remote ssh session (e.g. when using plink.exe from a Windows .bat file and passing inline commands to the Unix box) solves any issues regarding file/directory visibility & permission issues.

Note to plink users: if you're calling a script on Unix via plink and noticing that the script doesn't behave as expected...adding the "-i" may help debug/solve your problem. Again, note that some have claimed unwanted side-effects of this hack of which they/I'm unaware.