我的Windows计算机上有一个.bat
文件。此.bat
文件使用plink.exe
连接到Ubuntu计算机并执行.sh
脚本。但是,根据Plink的使用方式,我在脚本上会有不同的行为:
直接登录Ubuntu(亲自) - 脚本成功
ssh - 脚本成功
ssh通过Plink(通过调用plink.exe
)并从交互式shell调用脚本(它是Windows cmd.exe
中的Ubuntu shell) - 脚本成功
ssh通过.bat
然后调用Plink - 脚本失败
脚本失败,显示消息:
加载共享库时出现错误:libCint.so:无法打开共享对象文件:没有这样的文件或目录
其他帖子似乎是指libCint.so
的安装/权限问题,但我知道情况并非如此,因为脚本在其他实例中正常工作,如上所示。
以下是plink.exe
文件中的.bat
行:
plink.exe !plink_ssh_details! myscript
通过.bat
文件以这种方式调用上述脚本失败;再次注意,当直接从Ubuntu调用或者我通过cmd.exe
(使用plink.exe
)或Bitvise客户端直接进入Ubuntu时,它会成功。任何帮助将不胜感激。
答案 0 :(得分:1)
在其他情况下,您正在使用互动会话。
虽然默认情况下Plink使用非交互式会话,但在命令行中指定命令时。
您的脚本可能依赖于某些特定设置的环境变量(如PATH
)。
很可能只为交互式会话设置变量。可能是因为它们是在仅为交互式会话执行(源)的启动脚本中修改的。
解决方案是:
更正启动脚本以无条件地修改变量(即使是非交互式会话)。
修改脚本不依赖于环境变量。
或者您可以获取个人资料脚本,请参阅Unable to run shell script with ktutil command from Windows using PLINK。
强制Plink使用-t
开关
这不是推荐的解决方案,因为使用交互式会话来自动执行命令会带来令人讨厌的副作用。例如,请参阅Is there a simple way to get rid of junk values that come when you SSH using Python's Paramiko library and fetch output from CLI of a remote machine?
一些更加模糊的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.