#!/bin/sh #守护进程,接受2个参数 #para CMD 执行的命令 #pare ID 唯一标识改命令 if [ "$1" = "" -o "$2" = "" ];then echo "USAGE:deamon.sh CMD ID" exit 100 fi #创建文件夹 mkdir -p ./var CMD=$1 ID=$2 #守护循环 while [ 1 ] do #执行命令 $CMD & echo "`date +‘%Y%m%d %H:%M:%S‘`\t$CMD Is Start" #获取进程id并保存 pid="$!" echo $pid > ./var/$ID.pid echo "pid is $pid" wait $pid echo "`date`\t$CMD Is Stop" sleep 1 done
时间: 2024-10-23 12:14:25