#!/bin/bash
monitor(){
    # ps -ax | grep '/bin/webfxscand_2.0' | grep '/opt/' 
    list=`ps -ax | grep '/bin/webfxscand_2.0' | grep '/opt/' | awk '{print $1}'| sort`

    while true
    do
        for var in ${list[@]}
        do
            isExist=`ps -ax | grep ${var} | grep '/bin/webfxscand_2.0' | grep '/opt/' | wc -l`
            # ps -ax | grep ${var} | grep '/bin/webfxscand_2.0' | grep '/opt/'  | wc -l
            # echo ${var}'==>'${isExist}
            if [[ "${isExist}" == "0" ]] ; then
                echo 'restart'
                systemctl restart webfxscand_2.0.service
                exit 1
            fi
        done
        sleep 1
    done
}
export SANE_USB_WORKAROUND=1
/opt/apps/scanner-driver-btit-common/bin/webfxscand_2.0 &
sleep 1
monitor