大家好,我需要编写Unix Shell脚本来检查进程是否运行 如果进程正在运行,我需要检查两种检查类型 检查1:-如果进程正在运行,它将在/tmp/instancecheck.txt中创建一个文件,它将具有某些值 检查2:如果进程正在运行,它将有pid 在真实情况下,它工作正常,但在失败情况下,它不检查check2目录,否则将阻塞。请检查和帮助 脚本************
#!/bin/bash
#service=awsagent
service awsagent status | grep -i Instance-Id >/tmp/instancecheck.txt
_file="/tmp/instancecheck.txt"
if [ $( ps -ef | grep -v grep | grep awsagent | wc -l ) -ge 1 ];
then
echo first if statement done
if [ -s "$_file" ];
then
echo "$_file has some data."
echo process is workin fine
else
echo "$_file is empty."
# do something as file is empty
echo two checks are done service is not up you need to start it
fi
else
echo two checks done service looks fine
fi