Last active
April 26, 2019 14:01
-
-
Save peycho/6c7432d61ab82cab3e828378bae06f25 to your computer and use it in GitHub Desktop.
Monitoring linux process with bash script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
process="your-process-here" | |
run_command="command to start the process" | |
time_check="5" # time to check in sec. | |
while true ; do | |
proc_count=$(ps xa | grep -v grep | grep "$process" | wc -l) | |
if [ "$proc_count" == 0 ]; then | |
$run_command | |
echo "$(date) process $process was restarted." | |
fi | |
sleep $time_check | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Systemd config
Create example config in /etc/systemd/system/procx.service
Enable the service