K
K
Konstantin2017-09-20 14:56:38
bash
Konstantin, 2017-09-20 14:56:38

How to make BASH script keep track of hundreds of running processes?

Hello
everyone I made this sh-script for my specific task:

#! /bin/bash
if [ -e /home/user/pid/program1.pid ]
then
exit
else
nohup /home/user/start/program1 > /dev/null &
fi
if [ -e /home/user/pid/program1.pid ]
then
exit
fi
exit 0

It can be seen from the contents that the script monitors the PID of the running program, and if it is missing, the program restarts. The script is run by cron once a minute.
Attention to the question: how can I adapt this script for 50 programs of the same type. From program1 to program50.
Ask for expert advice.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
C
chupasaurus, 2017-09-20
@chupasaurus

To monitor the status of daemons, there is a supervisor and watchdog, the second one is part of systemd.

A
Alexander Chernykh, 2017-09-20
@sashkets

look at supervisord

S
sim3x, 2017-09-20
@sim3x

None
Use systemd

V
Vladimir Mukovoz, 2017-09-20
@castomi

In general, the answers that were given to me are very practical, but if you still need it that way, then you can work with the parameters.

#! /bin/bash
if [ -e $1 ];then
       exit
else
      nohup $2 > /dev/null &
fi
exit 0

and run the script like this Where $1 is the path to the pid, and $2 is the path to the program binary, if from your example, then like this
The parameters will be substituted for $1 and $2 in your script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question