title: "Jar简易自检程序"
createTime: 2022-01-05T14:44:01+08:00
updateTime: 2022-01-05T14:44:01+08:00
draft: false
author: "name"
tags: ["shell","java"]
categories: ["shell"]
description: "测试的"
jar 简易自检程序
- 脚本
text
#!/bin/sh
#line='cat ./pid/faceKuangshi-pid'
echo '自检程序开始'
temp_pid=0;
for line in `cat ./check_pid.txt`
do
pid_array[$temp_pid]=$(awk '{print}' $line)
let temp_pid++
done
echo '进程id:'
echo ${pid_array[*]}
temp_sh=0;
for line_sh in `cat ./check_start.txt`
do
#cat $line_sh
sh_array[$temp_sh]=$line_sh
let temp_sh++
done
echo '进程命令:'
echo ${sh_array[*]}
pid_length=${#pid_array[@]}
sh_length=${#sh_array[@]}
if [ $pid_length == $sh_length ];then
echo "自检查程序开始"
for ((i=0;i<$pid_length;i++))
do
echo ${pid_array[$i]} #为方便检查,加了打印
ps -p ${pid_array[$i]}
if [ $? -eq 0 ]; then
echo "app 存在"
else
echo "app 不存在"
${sh_array[$i]}
fi
done
else
echo '左右边的两个程序 不一样。'
fi
#ps -p 22
#if [ $? -eq 0 ]; then
#echo "app process exist"
#else
#echo "process exit"
#fi
#while ((n<=$(cat ip.txt|wc -l)))
#do
# ipaddr[$n]=$(cat ip.txt|sed -n "${n}p"|awk '{print $2}')
# ((n+=1))
#done
#n=`expr $n -- 1`
- check_pid 文件
text
/home/test/app1/pid/app1-pid
/home/test/app2/pid/app2-pid
/home/cjpt/app3/pid/app3-pid
- check_start 文件
/home/test/app1/start_app1.sh
/home/test/app2/start_app2.sh
/home/test/app3/start_app3.sh