Hi,
Thank you all your help.
At last my code works to some extent and could not read the txt file. Here is the error.
cat: cannot open /home/xxx/AppInstance_status.txt
Null message body; hope that's ok
___________________________
Here is the script I executed.
#!/bin/sh
logFile=~/AppInstance_status.txt
#store in a variable; easier to maintain
AppInstance=(xxx,aaa,ddd,ccc,xxx,cccfg)
for i in "${AppInstance[@]}" ;
do
AppInstance_status=`ps -ef | grep $i | grep -v grep`
if [ -z "$AppInstance_status" ] ;
then
echo "App Instance $i is not running . $(hostname) as on $(date)" >> $logFile
fi
done
cat $logFile | mail -s "Alert: AppInstance status check on Production "
xxxx@xxxx.com
The AppInstance_status.txt file is under the home directory at the same location where I run the scripts.
example: /home/xxx/scripts/AppInstance_status.txt
but it is trying to read from /home/xxx/AppInstance_status.txt. Do I need to change any where the location of the file? What I want it to do is to look for that txt file and run all 40 instances from the file and give the results if any of the instance is down.
It is too complicated but I badly need help in this script.
Please help and again thanks in advance.
Sai
---------- Post updated at 11:42 AM ---------- Previous update was at 11:35 AM ----------
I got the txt file moved to one upper level and my code started working but have a question to rectify it.
I want the txt file to display only the instances that are under stop status and not all the instances. Right now, it displays whatever in the txt without executing the command.
Can anyone help please.