开发者

jsch ChannelExec run a .sh script with nohup "lose" some commands

开发者 https://www.devze.com 2023-03-09 23:54 出处:网络
I hava a .sh script which glues many other scripts, called by jsch ChannelExec from a windows application.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号