vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I am fairly new to the world of AIX and would like to setup a simple shell script to monitor my server's uptime. More specifically, I would like to know when any of my servers have rebooted. I have written a script to do this, basically using the uptime utility, but I would like to know if there are any tools, such as Sun's kstat, that will give me boot time statistics. Here is what I am looking for, taken from a script on a Solaris box; LASTBOOT=`/usr/bin/kstat | grep boot_time | awk '{print \$2}'` This is the type of data that I am looking for; $ /usr/bin/kstat | grep boot_time boot_time 1100420233 I have read there is another utility similar on the AIX o/s - pstat. I have looked at the man pages and done some searches on this, but I am not seeing any syntax examples. Thanks. Bill |
| |||
| On 2005-01-31, BigBill <bill.scheuernstuhl@gmail.com> wrote: > shell script to monitor my server's uptime. More specifically, I would > like to know when any of my servers have rebooted. Isn't it *much* simpler to just add something like: echo "I've rebooted!" | mail admin@example.com to the boot scripts? -- Jurjen Oskam "E-mail has just erupted like a weed, and instead of considering what to say when they write, people now just let thoughts drool out onto the screen." - R. Craig Hogan |
| |||
| BigBill wrote: > I have read there is another utility similar on the AIX o/s - pstat. I > have looked at the man pages and done some searches on this, but I am > not seeing any syntax examples. > > Thanks. > > Bill > I suppose this will do: maba:/home/maba > last reboot reboot ~ Jan 18 17:58 reboot ~ Aug 12 09:56 ... Markus |
| |||
| This script is for Solaris based machines that I work with: ################################################## ########## # # Variable Definitions # # ################################################## ########## SERVER=`/usr/bin/hostname` ERROR=/tmp/up_mon.err FLAG=/tmp/up_mon.flag LASTBOOT=`/usr/bin/kstat | grep boot_time | awk '{print \$2}'` DATE=`/usr/local/bin/perl -e 'printf"%d\n", time;'` ################################################## ########### # # FUNCTION DEFINITION # # ################################################## ########### #Email script fail notice function function messagenotice { mailx -s "up_mon.ksh" user@noname.net < ${ERROR} /usr/bin/rm ${ERROR} exit 0 } ################################################## ########### # # EXECUTION # # ################################################## ########### #Check for flag if [ -f ${FLAG} ] then let "ii = ${DATE} - `cat ${FLAG}`" if [ ii -le 1800 ] then exit 0 else /usr/bin/rm ${FLAG} fi fi #Check to see if flag exists if [ -f /usr/bin/kstat ] then echo kstat exists! else echo "kstat does not exist on ${SERVER}." > ${ERROR} messagenotice fi #Check for reboot let "i = ${DATE} - ${LASTBOOT}" if [ ${i} -le 1800 ] then echo "Server ${SERVER} recently rebooted, please investigate." > ${ERROR} echo "`/usr/bin/who -b | awk '{print \$2,\$3,\$4,\$5,\$6}'`" >> ${ERROR} echo ${DATE} > ${FLAG} messagenotice fi exit 0 Instead of re-inventing the wheel, I would like to do exactly the same thing. |
| |||
| Here is an example of what has been suggested... ################################################## ################# # # Function Definition # ################################################## ################# function errornotice { mailx -s "{$hostname}" test@noname.net < ${ERROR} /bin/rm -f ${ERROR} exit 0 } ################################################## ################ # # Script Execution # ################################################## ################ uptime | grep days >> /dev/null if [[ $? -eq 1 ]]; then echo "System was booted less than 24 hours ago" errornotice else echo "System has been up more than 24 hours." exit fi HOURS=`uptime | awk '{print $3}' | cut -f1 -d:` MINUTES=`uptime | awk '{print $3}' | cut -f2 -d: | cut -f1 -d,` echo "The system has been up ${HOURS} hours and ${MINUTES} minutes." if [[ ${HOURS} -lt 1 ]]; then echo "The system was booted less than one hour ago. Take action now" fi if [[ ${MINUTES} -lt 30 && ${HOURS} -lt 1 ]]; then echo "The system was booted less than 30 minutes ago. Take action now" fi |
| |||
| BigBill wrote: > I am fairly new to the world of AIX and would like to setup a simple > shell script to monitor my server's uptime. More specifically, I would > like to know when any of my servers have rebooted. The "last" command supplies information about reboots. -- Gary R. Hook __________________________________________________ ______________________ Vocatus atque non vocatus deus aderit |
| ||||
| On 31 Jan 2005 10:44:05 -0800, "BigBill" <bill.scheuernstuhl@gmail.com> wrote: >I am fairly new to the world of AIX and would like to setup a simple >shell script to monitor my server's uptime. More specifically, I would >like to know when any of my servers have rebooted. > >I have written a script to do this, basically using the uptime utility, >but I would like to know if there are any tools, such as Sun's kstat, >that will give me boot time statistics. > >Here is what I am looking for, taken from a script on a Solaris box; > >LASTBOOT=`/usr/bin/kstat | grep boot_time | awk '{print \$2}'` > >This is the type of data that I am looking for; > >$ /usr/bin/kstat | grep boot_time >boot_time 1100420233 > >I have read there is another utility similar on the AIX o/s - pstat. I >have looked at the man pages and done some searches on this, but I am >not seeing any syntax examples. who -b Shows last boot time. |