jsch ChannelExec 使用 nohup "lose" 运行 .sh 脚本一些命令 [英] jsch ChannelExec run a .sh script with nohup "lose" some commands

查看:66
本文介绍了jsch ChannelExec 使用 nohup "lose" 运行 .sh 脚本一些命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .sh 脚本,它粘合了许多其他脚本,由 Windows 应用程序的 jsch ChannelExec 调用.

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();

如果我运行像nohup/foo/bar/foobar.sh >>/path/to/foo.log &"这样的命令,所有的长期工作(数据库操作、文件处理等)似乎都得到了丢了.

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.).

我检查了权限,$PATH,将 source/etc/profile 添加到我的 .sh 中,但这些都不起作用.

I checked the permissions, $PATH, add source /etc/profile to my .sh yet none of these works.

但是当我正常运行命令时(同步运行,在 Windows 上将所有回显输出打印到我的 java 客户端),一切顺利.

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.

提前致谢.

推荐答案

已解决!

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

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.

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

我的问题是,psql 和 pg_bulkload 将它们的输出打印到 err 流.

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 &

感谢 Atsuhiko Yamanaka,他创建了一个很棒的 JSch 库,并为 创建了 Paŭlo Ebermannhref="http://epaul.github.com/jsch-documentation/simple.javadoc/" rel="noreferrer">文档.

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

这篇关于jsch ChannelExec 使用 nohup "lose" 运行 .sh 脚本一些命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆