0

I have below solution to record a command and its output executed on a remote machine:

rexec:// -t -t /usr/bin/ssh -q -x -o StrictHostKeyChecking=no -2 \
         -l ${SSHUserName} -p 22 ${mainHost} \
 | tee >(/opt/oss/clilogging/bin/clilogging.sh para1 para2)

clilogging.sh will record each command and its output into a log file.
However, sometimes the last exited command and its output message "logout" is not written into the log file.

clilogging.sh is as follows:

#!/bin/bash

{
    while read R || [ -n "$R" ];do
        #e.g. 2013-08-19T09:58:08+0300
        timestamp=`date +%FT%T%z`;
        echo $timestamp $R;
    done
} > /tmp/xxx.log

Could anybody help me? Thanks a lot!

4

1 回答 1

1

感谢 thom 的评论,谢谢大家。
我已经找到了这个问题的解决方案。

需要在 clilogging.sh 开头添加以下代码

trap "" HUP

代码的意思是处理SIGHUP信号,这里我忽略了这个信号,那么clilogging.sh
不会立即退出,有机会处理所有缓冲区。

男人 7 信号

   Signal     Value     Action   Comment
   -------------------------------------------------------------------------
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
于 2013-11-07T05:01:29.663 回答