Skip to content

Instantly share code, notes, and snippets.

@hagun
Last active December 22, 2015 17:29
Show Gist options
  • Select an option

  • Save hagun/6506214 to your computer and use it in GitHub Desktop.

Select an option

Save hagun/6506214 to your computer and use it in GitHub Desktop.
stdin에서 line을 읽어서 netcat으로 원격지에 tcp 전송 첫번째 parameter를 이용해서 log format을 수정
#!/bin/bash
while read LINE; do
echo "$1:{${LINE}}" | nc 192.168.161.117 3333
done
#!/bin/bash
stream=`nc 192.168.161.117 3333`
while read LINE; do
echo "$1:{${LINE}}" >> $stream
done
#!/bin/bash
if [ "$#" -ne 2 ] || ! [ -f "$2" ]; then
echo "Usage: $0 SERVICENAME FILENAME" >&2
exit 1
fi
tail -n 1 -F $2 | awk -W interactive '{print "'$1':{",$0,"}"}' | while read LINE; do
echo "${LINE}" >> $stream || stream=`nc 192.168.161.117 3333`
done
@hagun
Copy link
Author

hagun commented Sep 11, 2013

v2에서 처리완료.
stream이 끊기는 경우에 다시 맺거나 하는 등의 에러 처리가 필요함.

@hagun
Copy link
Author

hagun commented Sep 11, 2013

v3에서는 tail을 내부적으로 처리하고, 사용법 노출, awk를 이용한 처리 등을 추가

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment