0

I have this following script running in my centos 7 server. its job is to run for-ever and check if xxx.js is alive, if crashed or killed, it has to restart it.

but since 3 days its failing to start my xxx.js unless i manually login to the server and apply $ ./myloop.sh &

root 23413 0.1 0.1 113252 1640 ? S Nov11 0:59 /bin/bash ./myloop.sh

Can anyone please check what is the BUG causing it to unable to execute the xxx.js when its not running / crashed?

#!/bin/bash
while :
do
  # 1
  xxx=$(pgrep -f "xxx.js")
  if [[ "$xxx" ]]; then
    log1="1 - running xxx.js $1 $2"
  else
    log1="1 - re-launch xxx.js $1 $2"
    ps aux | grep "xxx.js" | awk '{print $2}' | xargs kill
    sleep 1
    nohup node /var/www/html/sip-phone/xx/xxx.js &

  fi

  tt=$(date +"%Y-%m-%d %T")
  echo "$tt" "$log1"

  sleep 2
done
  • 1
    More immediately, the suicide problem; http://stackoverflow.com/questions/11375861/no-command-executed-after-performing-kill-command-in-shell-script – tripleee Nov 12 '15 at 04:49
  • No its not working, can you please check whats wrong in my script, it was working for 3 years. now since 3 days not working. –  Nov 12 '15 at 05:15
  • 1
    is myloop.sh running when you login to your server? Who is starting it? – cristi Nov 12 '15 at 09:22
  • YES - myloop.sh was running twice when i login to the server. root has executed the myloop.sh twice. –  Nov 12 '15 at 11:01

0 Answers0