Created
August 24, 2013 07:32
-
-
Save snt/6326669 to your computer and use it in GitHub Desktop.
Record a ssh log in Cygwin. Cygwin is slow on creating new process with `$( ... )`, so `tee` and add `$(date)` on each line would be extremely slow. run `sshlog` instead of `ssh`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sshlog () { | |
if [ "x$1" = "x" ]; then | |
echo "simple logging wrapper for ssh." | |
echo "use as usual ssh" | |
ssh | |
else | |
TARGET=$1 | |
mkdir -p ~/ssh-log | |
LOGFILE=~/ssh-log/$TARGET.$(date +%Y-%m-%d_%H.%M.%S).log | |
ssh $@ | python $HOME/timestamp-logger.py $LOGFILE | |
echo | |
echo "written log: $LOGFILE" | |
echo | |
fi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, datetime | |
logfile = open(sys.argv[1], "w") | |
stdin = sys.stdin | |
print "writing log:", sys.argv[1] | |
while 1: | |
try: | |
c = stdin.read(1) | |
if not c: | |
break | |
sys.stdout.write(c) | |
sys.stdout.flush() | |
logfile.write(c) | |
if c == "\n": | |
logfile.flush() | |
logfile.write(datetime.datetime.now().strftime("[%a %b %d %H:%M:%S.%f]")) | |
except EOFError: | |
break | |
logfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment