0

I have created script to check jar process is running or not, if not it will send mail. After executing it sends the mail if the process is not running.

#!/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

but after running the script getting below syntax error message in terminal.

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

Can anyone explain where and what thing am missing.

Prateek Naik
  • 2,522
  • 4
  • 18
  • 38
  • What are the values of `$CURTIME` and `$FILETIME` – Inian Mar 08 '18 at 11:53
  • 2
    You don't set `FILETIME` anywhere. By the way, it is dangerous to use uppercase variable names since they can collide with those used by the shell. For example, Bash has a `HOSTNAME` variable. Note that you are running this script under `sh` not `bash`, so loose the `bash` tag. – cdarke Mar 08 '18 at 13:51
  • 1
    You don't use `TIMEDIFF` anywhere, so why do you have that line of code anyway? – cdarke Mar 08 '18 at 13:59
  • Show the output of running the script with `bash -x `. See [How to debug a bash script?](https://unix.stackexchange.com/q/155551/56041), [How to debug a bash script?](https://stackoverflow.com/q/951336/608639), etc. – jww Mar 08 '18 at 18:35

0 Answers0