2015년 2월 5일 목요일

로깅과 함께 프로세스 시작

로깅과 함께 프로세스 시작

서버에 장시간 프로세스를 뛰어야 할 경우

vi executeWithTime.sh
chmode +x executeWithTime.sh
executeWithTime.sh
executeWithTime.sh 내용
#!/bin/bash

node ./imgUpdater.js  2>&1 | while IFS= read -r line; do echo "$(date) $line"; done >> ./test.log

설명

#!/bin/bash
배쉬를 인터프리터로 쓸거임
node ./imgUpdater.js 2>&1
2>&1 표준 에러를 표준 출력과 같은곳으로 설정
while IFS= read -r line; do echo “$(date) $line”; done
it’s a trick to prevent read from trimming whitespace at the beginning and and of the line. It sets IFS (bash’s Internal Field Separator, basically a list of whitespace characters) to empty for the read command. – Gordon Davisson
>> ./test.log
test.log 에 어팬드 하겠음