我有一个 .sh 脚本,它粘合了许多其他脚本,由 jsch ChannelExec 从 Windows 应用程序调用。
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("/foo/bar/foobar.sh");
channel.connect();
如果我运行“nohup/foo/bar/foobar.sh >>/path/to/foo.log &”之类的命令,所有长期作业(数据库操作、文件处理等)似乎都会丢失.
检查日志文件,只找到那些回显的东西(长期运行之前和之后,计算运行时间等)。
我检查了权限、$PATH,将源/etc/profile 添加到我的 .sh 但这些都不起作用。
但是当我正常运行命令时(同步运行,将所有回显输出打印到 Windows 上的 java 客户端),一切都很顺利。
这是一个非常具体的问题。 希望有经验的 friend 帮帮我。
提前致谢。
韩
最佳答案
解决了!
A different issue that often arises in this situation is that ssh is refusing to log off ("hangs"), since it refuses to lose any data from/to the background job(s).[6][7] This problem can also be overcome by redirecting all three I/O streams.
我的问题是,psql 和 pg_bulkload 将它们的输出打印到 err 流。
在我的脚本中,我没有重定向错误流。
通过将错误流重定向到同一个日志文件,一切都很顺利。
nohup foo.sh > log.log 2>&1 &
感谢山中敦彦,他创造了一个伟大的JSch library和 Paŭlo Ebermann 的 documentation .
关于ssh - jsch ChannelExec 使用 nohup "lose"一些命令运行 .sh 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224694/