프로세스 자동실행 및 실행 확인 스크립트

아래는 예시로 작성된 스크립트이며 환경에 맞게 수정하여 사용해주시길 바랍니다.

#!/bin/bash


# 실행할 프로세스 목록
processes=(
  "VBoxManage startvm Liunx_EX_Server-001 --type headless"
  "VBoxManage startvm Liunx_EX_Server-002 --type headless"
  "VBoxManage startvm Liunx_EX_Server-003 --type headless"
)


# 로그 파일 경로 및 이름
log_file="$HOME/process_checker.log"


# 각 프로세스가 실행 중인지 확인하고, 실행 중이 아니면 시작
for process in "${processes[@]}"; do
  if pgrep "$(echo "$process" | awk '{print $1}')" > /dev/null ; then
    echo "$(date '+%Y-%m-%d %H:%M:%S') $process is running." | tee -a "$log_file"
  else
    echo "$(date '+%Y-%m-%d %H:%M:%S') $process is not running. Starting $process..." | tee -a "$log_file"
    eval "$process &" | tee -a "$log_file"
  fi
done