1

service jbossas status -> command will check the jbossas status

jbossas(PID) is running (if jbossas is running)

jbossas is stopped (if jbossas is stopped)

#!/bin/ksh
#set -x
OUT_LOG="$1"

stus=$(service jbossas status)

var=$(ps -ef | grep -i '[/]jboss')

hname=$(hostname)

if [ -z "$var" ]; then

echo "service jbossas status" >>$OUT_LOG

echo "$stus" >>$OUT_LOG

mail -s "Please check for possbile impact $(stus)" [email protected] << $OUT_LOG

else

echo "'$stus'"

fi

NOTE:JBOSS process is not running on server so the o/p will be jboss is stopped .

If i execute the script manually in the shell(balck screen cmd prompt)

./jboss_status.ksh

Im receiving the mail with below subject and script is working fine

"Please check for possible impact jbossas is stopped"

but when i schedule it in the cron

* * * * * /aaa/jboss_status.ksh > /aaa/jboss_status.ksh.error 2>&1

Im receiving the mail with below subject "Please check for possbile impact" NOTE :"jbossas is stopped " is not getting printed at end of the subject

In getting below error in the error file created by cron

/aaa/jboss_status.ksh[20]: service: not found [No such file or directory]

The script is executing fine in cron but the output returned by the

command : service jbossas status 
op: jboss stopped 

is not getting printed in the subject

maulinglawns
  • 8,426
  • 2
  • 28
  • 36
star
  • 173
  • 2
  • 9

2 Answers2

1

You may need to source your bash_profile or bash_rc at the top of your script

on ubuntu

source /home/<user>/.bash_profile

some other linuxes

source /home/<user>/.bash_rc
0

Did you check the PATH variable for the user running the cron , it should have the path to the used script or its dependencies . Compare the paths with :

echo $PATH 

under the user which you run the script manually , and with the user which run the script in the cron .

Nico
  • 37
  • 4
  • Hi Begoul , Thanks for the quick revert . im running the script with my id manually as well scheduled cron under my id . if $path is the issue then why for cron job scheduled for this script under my id alone is throwing error . i guess the issue is something related to the line stus=$(service jbossas status) as cron is throwing error as as "service: not found [No such file or directory]" – star Nov 19 '16 at 09:34
  • `crontab -e` as user `SHELL=/bin/bash PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/bin/X11` The variable for SHELL mußt you adapt to your settigns. –  Nov 19 '16 at 10:46
  • @star just try it with the full path to `service` to verify. Check `which service` for that. – Jakob Lenfers Nov 19 '16 at 13:06
  • Hi jacob/Bahamut the script is working fine when ran manually but only while scheduling in cron im getting this error . if the issue is with PATH then why did the script work fine when i ran it manually ? – star Dec 02 '16 at 17:31