#!/bin/bash

shellPath=/www/_www/ysgame/tools/guard/shell/
logPath=/datasdc/logs/ysgame/log/
logFileName=$(date +"%Y%m%d%H").log
arrShellName=(\
"guardAppleScanBgqqprocess.sh" \
"guardAppleScanEnv1process.sh" \
"guardAppleScanEnv1processslave.sh" \
"guardAppleScanLocalcacherefresh.sh" \
"guardAppleScanProcessPayRecord.sh" \
"guardAppleScanProcessPayRecordysappcn.sh" \
"guardChannelcostV2RedisPush.sh" \
"guardGameErrlogCollectProcess.sh" \
"migglobal_tabledataclear.sh" \
"migglobal_tabledatarecordsGMSGCost.sh" \
"replayglobaltostat.sh" \
"replaystattoglobal_tb_ysgame.sh" \
"smstart.sh" \
"smstartgame.sh" \
"startHandleBatch.sh" \
"tableclear.sh"\
)
#和上面数组要对应
arrShellLogName=(\
"nohup_bgqq.log" \
"nohup_env1process.log" \
"nohup_env1processslave.log" \
"nohup_localCacheRefresh.log" \
"nohup_payrecord.log" \
"nohup_payrecord_ysappcn.log" \
"nohup_channelCostRedisPush.log" \
"nohup_gameErrLogCollect.log" \
"nohup_tabledataclear.log" \
"nohup_recordsGMSGCost.log" \
"nohup_tostat.log" \
"nohup_toglobal.log" \
"nohup_smstart.log" \
"nohup_smstartgame.log" \
"nohup_startHandleBatch.log" \
"nohup_tableclear.log" \
)
#while true
#do
#    logFileName=onekey_$(date +"%Y%m%d%H").log
#done
#  function funcLog() {
#    echo "$(date +"%Y-%m-%d %H:%M:%S") ${1} " >> ${logPath}${logFileName}
#  }
echo "当前脚本数量:${#arrShellName[*]}"
for (( i = 0; i < ${#arrShellName[*]}; i++ ))
do
  processList=`ps aux|grep "${arrShellName[$i]}"|grep -v "grep"|awk '{print $2}'`
  if [ "$processList" = "" ]; then
      nohup ${shellPath}${arrShellName[$i]} >> ${logPath}${arrShellLogName[$i]} 2>&1 &
      echo "${arrShellName[$i]} 启动成功"
  else
    echo "${arrShellName[$i]} 脚本已经在运行，请勿重复运行,进程ID:${processList}"
  fi

#    shellProcessCount=$(ps aux|grep "${arrShellName[$i]}"|grep -v "grep"|grep -v "vim"|grep -v "vi"|wc -l)
#    echo ${arrShellName[$i]}" 脚本数量：${shellProcessCount}"
#    #脚本数量大于0,结束脚本重新运行
#    if [ "$shellProcessCount" -gt 0 ]; then
#        processList=`ps aux|grep "${arrShellName[$i]}"|grep -v "grep"|awk '{print $2}'`
#        for pid in $processList
#        do
#          echo "结束pid:"$pid
#          kill -9 $pid
#        done
#    fi
#    ". ${arrShellName[$i]}" >> ${logPath}${arrShellLogName[$i]} 2>&1
#    shellProcessCount=$(ps aux|grep "${arrShellName[$i]}"|grep -v "grep"|grep -v "vim"|grep -v "vi"|wc -l)
#    echo ${arrShellName[$i]}" 脚本数量：${shellProcessCount}"
#flock -xn ${lockFilePath}${arrShellName[$i]}.lock -c " nohup ${shellPath}${arrShellName[$i]} >> ${logPath}${arrShellLogName[$i]} 2>&1 &"
done

#shellProcessCount=$(ps aux|grep "${arrShellName[$i]}"|grep -v "grep"|grep -v "vim"|grep -v "vi"|wc -l)
#echo ${arrShellName[$i]}" 脚本数量：${shellProcessCount}"
#nohup ${shellPath}guardAppleScanBgqqprocess.sh >> ${logPath}nohup_bgqq.log 2>&1 &
#nohup ${shellPath}guardAppleScanEnv1process.sh >> ${logPath}nohup_env1process.log 2>&1 &
#nohup ${shellPath}guardAppleScanEnv1processslave.sh >> ${logPath}nohup_env1processslave.log 2>&1 &
#guardAppleScanLocalcacherefresh.sh >> ${logPath}nohup_localCacheRefresh.log 2>&1
#nohup ${shellPath}guardAppleScanProcessPayRecord.sh >> ${logPath}nohup_payrecord.log 2>&1 &
#nohup ${shellPath}guardAppleScanProcessPayRecordysappcn.sh >> ${logPath}nohup_payrecord_ysappcn.log 2>&1 &
#nohup ${shellPath}guardChannelcostV2RedisPush.sh >> ${logPath}nohup_channelCostRedisPush.log 2>&1 &
#nohup ${shellPath}guardGameErrlogCollectProcess.sh >> ${logPath}nohup_gameErrLogCollect.log 2>&1 &
#nohup ${shellPath}migglobal_tabledataclear.sh >> ${logPath}nohup_tabledataclear.log 2>&1 &
#nohup ${shellPath}migglobal_tabledatarecordsGMSGCost.sh >> ${logPath}nohup_recordsGMSGCost.log 2>&1 &
#nohup ${shellPath}replayglobaltostat.sh >> ${logPath}nohup_tostat.log 2>&1 &
#nohup ${shellPath}replaystattoglobal_tb_ysgame.sh >> ${logPath}nohup_toglobal.log 2>&1 &
#nohup ${shellPath}smstart.sh >> ${logPath}nohup_smstart.log 2>&1 &
#nohup ${shellPath}smstartgame.sh >> ${logPath}nohup_smstartgame.log 2>&1 &
#nohup ${shellPath}startHandleBatch.sh >> ${logPath}nohup_startHandleBatch.log 2>&1 &
#nohup ${shellPath}tableclear.sh >> ${logPath}nohup_tableclear.log 2>&1 &

#echo "启动成功"


