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!