___  ___    _ _    _  _ _____   _____
 / __|/ _ \  | | |  | || |_ _\ \ / / __|
| (_ | (_) | |_  _| | __ || | \ V /| _|
 \___|\___/    |_|  |_||_|___| \_/ |___|

 --- A GOPHER-LIKE INTERFACE FOR HIVE BLOCKCHAIN ---

프로그램 감시하다가 다운되면 다시 살리는 쉘 스크립트

BY: @south-man | CREATED: May 30, 2018, 11:50 a.m. | VOTES: 1 | PAYOUT: $0.00 | [ VOTE ]

깃 허브에도 올라가 있는데, 이전에 소개드린 바이넨스 자동 매매 프로그램이 죽었을 때 다시 살리는 쉘 스크립트입니다.
https://github.com/llejo3/binance-trading/blob/master/tradingMonitor.sh

#!/bin/bash

log=./logs/monitor.log
SLEEP_SECONDS=300     # 대기 시간
BASIC_GAP_SECONDS=300 # 비교를 위한 기준 간격 시간

while [ 1 ] 
do
  # 로그가 1분정도마다 남기게 되어 있어서 INFO로 남긴 데이터 중에서 마지막 시간을 가져온다.
  last_date=`tail -200 ./logs/process.log | grep INFO | tail -1 | cut -c 2-20`
  diff_seconds=$(($(date -d now +%s) - $(date -d "$last_date" +%s)))        
  if [ $diff_seconds -gt $BASIC_GAP_SECONDS ]  # 로그가 없으면 다시 실행              
  then
    # process ID를 구한다음 프로세스를 종료시킨 다음 다시 시작한다.
    PROCESS=`ps -ef|grep process|grep -v grep | awk '{print $2}'`
    kill -9 $PROCESS
    wait
    now_date=`date '+%Y-%m-%d %H:%M:%S'`
    echo "$now_date : Process restarted." >> $log
    ./startProcess.sh
    wait
  fi
  sleep $SLEEP_SECONDS
done

[IMAGE: https://cdn.steemitimages.com/DQmNdmJKRFtDQr5RvEUZZEaPESa2ghFc8MMN1gm88WsM2xf/image.png]

TAGS: [ #monitor ] [ #shell ] [ #re-live ] [ #kr ] [ #unix ]

Replies

NO REPLIES FOUND.

[ BACK TO TRENDING ] [ BACK TO MENU ]
CMD>