shell脚本创建多个终端启动多个算法

1、目标

        创建.sh脚本,实现三个算法自启动功能。并实时进行监测进程,当进程断开,则重新自启动算法。

2、实现

#! /bin/bash

export LD_LIBRARY_PATH=/home/mzd/project/ken/vulkan/1.2.162.1/x86_64/lib:./mylib:/home/mzd/project/ken/hikvisionSDK/CH-HCNetSDKV6.1.9.4_build20220413_linux64/lib:/home/mzd/project/ken/json/build/lib:$LD_LIBRARY_PATH
while true
do

    #############################  contral camera  #############################
	{
    monitor1=`ps -ef | grep contral_cam | grep -v grep | wc -l `
    if [ $monitor1 -eq 0 ]
    then
        echo "contral_cam_31_32_ program is not running, restart it"
		gnome-terminal -x bash -c "/home/mzd/project/ken/contral_cam/v4/test.sh;exec bash"
    else
        echo "contral_cam_31_32_ program is running"
    fi
	}&
    sleep 10

    #############################  wlxd  #############################
	{
    monitor2=`ps -ef | grep wlxd | grep -v grep | wc -l `
    if [ $monitor2 -eq 0 ]
    then
        echo "wlxd program is not running, restart it"
        gnome-terminal -x bash -c "/home/mzd/project/ken/wailaxd/v4.1/test.sh;exec bash"
    else
        echo "wlxd program is running"
    fi
	}&
    sleep 7

    #############################  people detection  #############################    
	{
    monitor3=`ps -ef | grep people_detection_saveImg_jsonk | grep -v grep | wc -l `
    if [ $monitor3 -eq 0 ]
	
    then
        echo "people_detection_saveImg_jsonk program is not running, restart it"
        gnome-terminal -x bash -c "/home/mzd/project/ken/fixes_area_peopledetection/v8/test.sh;exec bash"
    else
        echo "people_detection_saveImg_jsonk program is running"
    fi
	}&
    sleep 7
    
    #############################  hook rush top  #############################    
	{
    monitor4=`ps -ef | grep hook_rush_top_json | grep -v grep | wc -l `
    if [ $monitor4 -eq 0 ]
    then
        echo "hook_rush_top_json program is not running, restart it"
		gnome-terminal -x bash -c "/home/mzd/project/ken/hook_rush_top/v5/test.sh;exec bash"
    else
        echo "hook_rush_top_json program is running"
    fi
	}&
    sleep 7
    #############################  protest  #############################    
done



         上述有四个可执行程序contral_cam,wlxd,people_detection_saveImg_jsonk,hook_rush_top_json,实现了依次启动这四个算法,当contral_cam进程断开,则杀死四个进程,并重新依次启动四个算法。

你可能感兴趣的:(linux,bash,运维)