jsch ChannelExec 使用 nohup “lose” 运行 .sh 脚本一些命令
我有一个 .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 客户端),一切都很顺利。
这是一个非常具体的问题。 希望有经验的人可以帮帮我。
提前致谢。
汉族
I hava a .sh script which glues many other scripts, called by jsch ChannelExec from a windows application.
Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("/foo/bar/foobar.sh");
channel.connect();
if I run the command like "nohup /foo/bar/foobar.sh >> /path/to/foo.log &", all the long term jobs(database operations, file processing etc.) seems to get lost.
checking the log file, only find those echo stuffs(before and after a long term operation, calculate running time etc.).
I checked the permissions, $PATH, add source /etc/profile to my .sh yet none of these works.
but when I run the command normally (sync run, print all echo outputs to my java client on windows),all the things goes well.
it's a really specific prob.
Hope someone with experience can help me out.
thank in advance.
Han
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!
我的问题是,psql 和 pg_bulkload 打印他们的输出到 err 流。
在我的脚本中,我没有重定向错误流。
通过将错误流重定向到同一个日志文件,一切都很顺利。
感谢 Atsuhiko Yamanaka 创建了一个出色的 JSch 库,感谢 Paŭlo Ebermann 的 文档。
Solved!
My prob is, psql and pg_bulkload print their outputs to err stream.
In my script, I didn't redirect err streams.
Everything went fine by also redirecting err streams to the same log file.
Thanks to Atsuhiko Yamanaka, he created a great JSch library, and Paŭlo Ebermann for the documentation.