I tried that as well, the situation I am having is I have 7 applications running on this server and each app uses a different IP, so what I am doing is if the app is app4 then do
/sbin/ip addr ls eth0 | awk '/inet / {print $2, $8}'
133.8.5.9/16 eth0
133.8.5.8/16 eth0:1
133.8.5.7/16 eth0:2
133.8.5.6/16 eth0:3
133.8.5.5/16 eth0:4
133.8.5.4/16 eth0:5
133.8.5.3/16 eth0:6
133.8.5.2/16 eth0:7
if it is app4 then give me the IP to eth0:4, but this script should work for every app.
here is an example of my script:
JBOSS=$1
JBOSS_ENV=`echo -e ${JBOSS} | awk '{print substr($0,7)}'`
JBOSS_ETH=`echo -e ${JBOSS} | awk '{print substr($0,10)}'`
JBOSS_SVR=`uname -n`
JBOSS_IP=`/sbin/ifconfig eth0:${JBOSS_ETH} | sed -n '/inet addr/s/.*addr.\([^ ]*\) .*/\1/p'`
JBOSS_PID=`ps aux | grep -v grep | grep -v bash | grep $1 | awk '{print $2}'`
JBOSS_TMP='/home/tomcat/scripts/'${JBOSS_ENV}'.jboss_thread_dump.html'
SCRIPT_PATH=`dirname "$0"`; SCRIPT_PATH=`eval "cd \"$SCRIPT_PATH\" && pwd"`
if [[ -z ${JBOSS_PID} ]]; then
echo "Subject: ${JBOSS_ENV} JBOSS Thread Dump from ${JBOSS_SVR}" >> $JBOSS_TMP
echo -e "\nContent-Type: text/html; charset="us-ascii"" >> $JBOSS_TMP
echo -e "\nJBOSS Script Path: ${SCRIPT_PATH}\n\nJBOSS Environment: ${JBOSS_ENV}\n" >> $JBOSS_TMP
echo "<html><body>" >> $JBOSS_TMP
/usr/local/${JBOSS}/jboss-soa-p.5.0.0/jboss-as/bin/twiddle.sh --server=${JBOSS_IP} --user=***** --password=***** invoke jboss.system:type=ServerInfo listThreadDump >> $JBOSS_TMP
echo "</body></html>" >> $JBOSS_TMP
cat $JBOSS_TMP | grep -i "FOUND DEADLOCK" > /dev/null; status=$?
if [ $status = 0 ]; then
cat $JBOSS_TMP | mail -s "${JBOSS} ${JBOSS_SVR} DEADLOCK FOUND" MYEMAILADDRESS
fi
cat $JBOSS_TMP | grep "ERROR" > /dev/null; status=$?
if [ $status = 0 ]; then
cat $JBOSS_TMP | mail -s "${JBOSS} ${JBOSS_SVR} ERROR FOUND" MYEMAILADDRESS fi
/usr/sbin/sendmail MYEMAILADDRESS < $JBOSS_TMP
rm $JBOSS_TMP
exit
fi
The script works this way, but I am trying to use IP instead of ifconfig. Also I want to elimnate all the extra echo's and unnecessary code.