我已创建脚本来检查jar进程是否正在运行,如果没有,它将发送邮件。执行后,如果进程未运行,则发送邮件。
#!/bin/sh
check_if_running()
{
echo "Checking to make sure push processor is running"
determine_push_pid
if [ "$PID" != "" ]
then
echo "Found push processor running under process ID {$PID}"
else
echo "Can't determine process ID for push processor, "
# start_push_processor
send_email "There is no process running on :-> $BOXNAME"
fi
}
determine_push_pid()
{
PID=`ps -ef | grep ams_services | grep java | grep -v DupdateProfiles | awk -F' ' ' { print $2 } '`
if [ "$PID" != "" ]
then
echo "Process ID for push processor is {$PID}"
fi
}
start_push_processor()
{
echo "Starting push processor"
nohup java -Dspring.profiles.active=dev -Xms2G -Xmx2G -jar #$JARFILE & 1>>$LOGFILE 2>>$echoFILE
echo "Sleeping for $SLEEPSECONDS seconds"
sleep $SLEEPSECONDS
determine_push_pid
if [ "$PID" == "" ]
then
echo "Can't determine new process ID for push processor, did it start?"
send_email "Tried to start push processor, but couldn't on $BOXNAME"
else
echo "New PID for push processor is {$PID}"
fi
}
send_email()
{
DATA=$(cat <<EOF
{
"occurrenceTime":"$DATE",
"systemIdentity":
{
"ip":"$IP"
},
"eventType":"36c170f1-1338-4346-9d5b-737841a22166",
"shortDesc":"Roster Alignment Alert !!",
"properties":
{
"description":"$*",
"env":"$OPS_ENVIRONMENT",
"hostname":"$HOSTNAME"
}
}
EOF
)
### echo "$*"
echo "$*" | mail -s "Roster Alignement Process Warning !!! " roster@mail.com
echo "### Exiting with error after sending email"
exit 1
}
SCRIPTNAME="Roster_Service.sh"
PROGNAME="ams_services"
IP=`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
BOXNAME="$OPS_CI_NAME ($OPS_ENVIRONMENT) ($IP)"
ENV=$OPS_ENVIRONMENT
SLEEPSECONDS=5
ACTIVITYSECONDS=600
CURTIME=$(date +%s)
TIMEDIFF=$(expr $CURTIME - $FILETIME)
JARFILE=""
P='%'
SCRIPTPID=$$
PID=""
DATE=`date +%s`
HOSTNAME=`hostname`
check_if_running
exit 0
但是在终端中运行脚本后面的syntax error
消息之后。
expr: syntax error
### Starting Roster_Service.sh in dev
Checking to make sure push processor is running
Can't determine process ID for push processor,
### Exiting with error after sending email
任何人都可以解释缺少的地方和内容。