質問

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!

役に立ちましたか?

解決

Thanks thom's comment and thank you all.
I have found the solution of this issue.

Need add following code at the begining of clilogging.sh

trap "" HUP

The meaning of code is to handle SIGHUP signal, here I ignore this signal, then clilogging.sh
will not quit immediately and have the chance to handle all buffer.

man 7 signal

   Signal     Value     Action   Comment
   -------------------------------------------------------------------------
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top