jsch ChannelExec 使用 nohup “lose” 运行 .sh 脚本一些命令

发布于 2024-11-14 00:18:38 字数 551 浏览 9 评论 0原文

我有一个 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2024-11-21 00:18:38

解决了!

经常出现的一个不同问题
这种情况是ssh拒绝
注销(“挂起”),因为它拒绝
丢失来自/到的任何数据
后台作业。[6][7]这个问题
也可以通过重定向来克服
所有三个 I/O 流。

来自
http://en.wikipedia.org/wiki/Nohup

我的问题是,psql 和 pg_bulkload 打印他们的输出到 err 流。

在我的脚本中,我没有重定向错误流。

通过将错误流重定向到同一个日志文件,一切都很顺利。

nohup foo.sh > log.log 2>&1 &

感谢 Atsuhiko Yamanaka 创建了一个出色的 JSch 库,感谢 Paŭlo Ebermann 的 文档

Solved!

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.

from
http://en.wikipedia.org/wiki/Nohup

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.

nohup foo.sh > log.log 2>&1 &

Thanks to Atsuhiko Yamanaka, he created a great JSch library, and Paŭlo Ebermann for the documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文