sunhux
asked on
Sun Solaris Unix Shell script that adds 2 to a string numeric and checks last value for changes
Question: Currently our Sun E450 could detect room temperature ie ambient (from
"prtdiag -v" and I've observed that it's consistently reporting about 2 Celsius lower
than the general DC room temperature :
# prtdiag -v | grep -i ambie
AMBIENT 19
"date" command in this Solaris 8 box's format is :
# date
Sat May 9 06:06:58 SGT 2009
I'll need a Shell script that run every 1 minute (I'll put this into the crontab as
* * * * * /path/script_name) that will do the following :
I'll need this Shell script to be able to notify/email me when AMBIENT is :
(>= 21 AND there's a change from the reading one minute ago) OR
(<= 20 AND the temperature recorded one minute ago is >= 21)
Above script basically notifies me once only (not repeatedly) when temperature
hits 21 C but if temperature keep going up (at levels above 21 C) it will keep emailing/
notifying me.
This script only notify me once when temperature go below 21 C (but only notify
once and not repeatedly and it will stop notifying if room temperature stays below
20 C)
the script in pseudo codes :
Currentdatetime=yyyymmdd:h hmm (24 hr format)
echo RoomTemp + " " + Currentdatetime >> yyyymmdd_outputfile
add 2 to the value given by "prtdiag -v | grep AMBIENT" (call this variable RoomTemp
if RoomTemp equals or exceeds 21
check RoomTemp vs last_temperature recorded in last line of yyyymmdd_outputfile
if RoomTemp equal or exceed 21 AND is higher than last_temperature
email to myemail the value Currentdatetime+" "+":Room temp is now "+RoomTemp
endif
if last_temperature in last line of yyyymmdd_outputfile >= 21 and RoomTemp is <=20
email to myemail the value Currentdatetime+" "+":Room temp now is down to "+RoomTemp
endif
exit
"prtdiag -v" and I've observed that it's consistently reporting about 2 Celsius lower
than the general DC room temperature :
# prtdiag -v | grep -i ambie
AMBIENT 19
"date" command in this Solaris 8 box's format is :
# date
Sat May 9 06:06:58 SGT 2009
I'll need a Shell script that run every 1 minute (I'll put this into the crontab as
* * * * * /path/script_name) that will do the following :
I'll need this Shell script to be able to notify/email me when AMBIENT is :
(>= 21 AND there's a change from the reading one minute ago) OR
(<= 20 AND the temperature recorded one minute ago is >= 21)
Above script basically notifies me once only (not repeatedly) when temperature
hits 21 C but if temperature keep going up (at levels above 21 C) it will keep emailing/
notifying me.
This script only notify me once when temperature go below 21 C (but only notify
once and not repeatedly and it will stop notifying if room temperature stays below
20 C)
the script in pseudo codes :
Currentdatetime=yyyymmdd:h
echo RoomTemp + " " + Currentdatetime >> yyyymmdd_outputfile
add 2 to the value given by "prtdiag -v | grep AMBIENT" (call this variable RoomTemp
if RoomTemp equals or exceeds 21
check RoomTemp vs last_temperature recorded in last line of yyyymmdd_outputfile
if RoomTemp equal or exceed 21 AND is higher than last_temperature
email to myemail the value Currentdatetime+" "+":Room temp is now "+RoomTemp
endif
if last_temperature in last line of yyyymmdd_outputfile >= 21 and RoomTemp is <=20
email to myemail the value Currentdatetime+" "+":Room temp now is down to "+RoomTemp
endif
exit
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Think there's a problem with outfile :
# outfile="`/usr/bin/date +%Y%M%D`.log"
# echo $outfile
20092705/22/09.log
as the script gave following error when run using "ksh -v scriptname" :
>ksh -v chktemp.sh
ORACLE_HOME=`awk -F":" '/^[a-zA-Z]/{print $2}' /etc/oratab|head -1`
LD_LIBRARYPATH=$ORACLE_HOM
MANPATH=/usr/perl5/man:/us
export PATH=/usr/bin:/usr/sbin:/u
/opt/netque/pse:$ORACLE_HO
:/opt/hpnpl/bin:/opt/hpnpl
ORACLE_HOME MANPATH
[ -f /adm/remote_oracle/bin/pro
HOSTNAME=`/usr/bin/hostnam
export PS1='$HOSTNAME:$PWD >'
export UDTBIN=/usr/ud52/bin UDTHOME=/usr/ud52
alias bdump_prodcts='cd /oracle/product/8.1.7/admi
alias bdump_prodgbr='cd /oracle/product/8.1.7/admi
alias bdump_prodldau='cd /oracle/product/8.1.7/admi
alias arch_prodcts='cd /oracle/archive/prodcts'
alias arch_prodgbr='cd /oracle/archive/prodgbr'
alias arch_prodldau='cd /oracle/archive/prodldau'
alias prtdiag='/usr/platform/sun
alias jetadmin='cd /opt/hpnpl/admin/;jetadmin
alias enstall='cd /opt/netque/pse;enstall -m'
set -o vi
sqlplus ()
{
echo $*
export oracle_sid=$ORACLE_SID
su - oracle -c "export ORACLE_SID=$oracle_sid;sql
}
#/bin/sh
myemail_addr="goh_pit_ong@
outfile="`/usr/bin/date +%Y%M%D`.log"
# Get the current temp and adjust....
curTmp=`prtdiag -v |grep AMBIENT| sed -e 's/.*AMBIENT[ ]*\([0-9]*\).*/\1/'`
curtmp=`expr $curtmp + 2`
expr: syntax error
# Get the last temp.
if [ -f outfile ] ; then
prevTmp=`tail -1 outfile|sed -e 's/^\([0-9]*\) .*/\1/'`
else
touch ${outfile}
prevTmp=0
fi
touch: 20092805/22/09.log cannot create
#
# record temperature
#
echo "${curTmp} `/usr/bin/date +%Y%M%D:%R`" >> ${outfile}
chktemp.sh[22]: 20092805/22/09.log: cannot create
#
# email as necessary...
if [ ${curtmp} -eq ${prevTmp} ] ; then
exit 0
fi
chktemp.sh[26]: test: argument expected
if [ ${curTmp} -eq 21 -a ${curTmp} -gt ${prevTmp} ] ; then
msg="Warning: temperature is 21"
elif [ ${curTmp} -gt 21 -a ${curTmp} -gt {prevTmp} ] ; then
msg="Warning: temperature is increasing (${prevTmp -> ${curTmp})"
elif [ ${curTmp} -lt 21 -a ${prevTmp} -ge 21 ] ; then
msg="Temperature is done to ${curTmp}"
else
exit 0
fi
chktemp.sh[32]: {prevTmp}: syntax error
ASKER
Even after I've hardcoded as follows, got another error :
outfile="/tmp/a.a"
# ksh -v chktemp.sh
ORACLE_HOME=`awk -F":" '/^[a-zA-Z]/{print $2}' /etc/oratab|head -1`
LD_LIBRARYPATH=$ORACLE_HOM E/lib
MANPATH=/usr/perl5/man:/us r/bin/man: /usr/man:/ opt/hpnpl/ man
export PATH=/usr/bin:/usr/sbin:/u sr/local/b in:/usr/pl atform/SUN W,Ultra-4/ sbin:\
/opt/netque/pse:$ORACLE_HO ME/bin:.\
:/opt/hpnpl/bin:/opt/hpnpl /admin:/us r/lib/osa/ bin:/usr/o penwin/bin :/opt/VRTS vmsa/bin:/ usr/lib\
ORACLE_HOME MANPATH
[ -f /adm/remote_oracle/bin/pro c ] && export PATH=$PATH:/adm/remote_ora cle/bin
HOSTNAME=`/usr/bin/hostnam e`
export PS1='$HOSTNAME:$PWD >'
export UDTBIN=/usr/ud52/bin UDTHOME=/usr/ud52
alias bdump_prodcts='cd /oracle/product/8.1.7/admi n/prodcts/ bdump'
alias bdump_prodgbr='cd /oracle/product/8.1.7/admi n/prodgbr/ bdump'
alias bdump_prodldau='cd /oracle/product/8.1.7/admi n/prodldau /bdump'
alias arch_prodcts='cd /oracle/archive/prodcts'
alias arch_prodgbr='cd /oracle/archive/prodgbr'
alias arch_prodldau='cd /oracle/archive/prodldau'
alias prtdiag='/usr/platform/sun 4u/sbin/pr tdiag'
alias jetadmin='cd /opt/hpnpl/admin/;jetadmin '
alias enstall='cd /opt/netque/pse;enstall -m'
set -o vi
sqlplus ()
{
echo $*
export oracle_sid=$ORACLE_SID
su - oracle -c "export ORACLE_SID=$oracle_sid;sql plus $*"
}
#/bin/sh
myemail_addr="goh_pit_ong@ sla.gov.sg "
# outfile="`/usr/bin/date +%Y%M%D`.log"
outfile="/tmp/a.a"
# Get the current temp and adjust....
curTmp=`prtdiag -v |grep AMBIENT| sed -e 's/.*AMBIENT[ ]*\([0-9]*\).*/\1/'`
curtmp=`expr $curtmp + 2`
expr: syntax error
# Get the last temp.
if [ -f outfile ] ; then
prevTmp=`tail -1 outfile|sed -e 's/^\([0-9]*\) .*/\1/'`
else
touch ${outfile}
prevTmp=0
fi
#
# record temperature
#
echo "${curTmp} `/usr/bin/date +%Y%M%D:%R`" >> ${outfile}
#
# email as necessary...
if [ ${curtmp} -eq ${prevTmp} ] ; then
exit 0
fi
chktemp.sh[28]: test: argument expected
if [ ${curTmp} -eq 21 -a ${curTmp} -gt ${prevTmp} ] ; then
msg="Warning: temperature is 21"
elif [ ${curTmp} -gt 21 -a ${curTmp} -gt {prevTmp} ] ; then
msg="Warning: temperature is increasing (${prevTmp -> ${curTmp})"
elif [ ${curTmp} -lt 21 -a ${prevTmp} -ge 21 ] ; then
msg="Temperature is done to ${curTmp}"
else
exit 0
fi
chktemp.sh[34]: {prevTmp}: syntax error
outfile="/tmp/a.a"
# ksh -v chktemp.sh
ORACLE_HOME=`awk -F":" '/^[a-zA-Z]/{print $2}' /etc/oratab|head -1`
LD_LIBRARYPATH=$ORACLE_HOM
MANPATH=/usr/perl5/man:/us
export PATH=/usr/bin:/usr/sbin:/u
/opt/netque/pse:$ORACLE_HO
:/opt/hpnpl/bin:/opt/hpnpl
ORACLE_HOME MANPATH
[ -f /adm/remote_oracle/bin/pro
HOSTNAME=`/usr/bin/hostnam
export PS1='$HOSTNAME:$PWD >'
export UDTBIN=/usr/ud52/bin UDTHOME=/usr/ud52
alias bdump_prodcts='cd /oracle/product/8.1.7/admi
alias bdump_prodgbr='cd /oracle/product/8.1.7/admi
alias bdump_prodldau='cd /oracle/product/8.1.7/admi
alias arch_prodcts='cd /oracle/archive/prodcts'
alias arch_prodgbr='cd /oracle/archive/prodgbr'
alias arch_prodldau='cd /oracle/archive/prodldau'
alias prtdiag='/usr/platform/sun
alias jetadmin='cd /opt/hpnpl/admin/;jetadmin
alias enstall='cd /opt/netque/pse;enstall -m'
set -o vi
sqlplus ()
{
echo $*
export oracle_sid=$ORACLE_SID
su - oracle -c "export ORACLE_SID=$oracle_sid;sql
}
#/bin/sh
myemail_addr="goh_pit_ong@
# outfile="`/usr/bin/date +%Y%M%D`.log"
outfile="/tmp/a.a"
# Get the current temp and adjust....
curTmp=`prtdiag -v |grep AMBIENT| sed -e 's/.*AMBIENT[ ]*\([0-9]*\).*/\1/'`
curtmp=`expr $curtmp + 2`
expr: syntax error
# Get the last temp.
if [ -f outfile ] ; then
prevTmp=`tail -1 outfile|sed -e 's/^\([0-9]*\) .*/\1/'`
else
touch ${outfile}
prevTmp=0
fi
#
# record temperature
#
echo "${curTmp} `/usr/bin/date +%Y%M%D:%R`" >> ${outfile}
#
# email as necessary...
if [ ${curtmp} -eq ${prevTmp} ] ; then
exit 0
fi
chktemp.sh[28]: test: argument expected
if [ ${curTmp} -eq 21 -a ${curTmp} -gt ${prevTmp} ] ; then
msg="Warning: temperature is 21"
elif [ ${curTmp} -gt 21 -a ${curTmp} -gt {prevTmp} ] ; then
msg="Warning: temperature is increasing (${prevTmp -> ${curTmp})"
elif [ ${curTmp} -lt 21 -a ${prevTmp} -ge 21 ] ; then
msg="Temperature is done to ${curTmp}"
else
exit 0
fi
chktemp.sh[34]: {prevTmp}: syntax error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
have to purchase it which is difficult in our budget-conscious environment