calculate server uptime in % (99.98), using ksh script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calculate server uptime in % (99.98), using ksh script
# 1  
Old 06-20-2008
calculate server uptime in % (99.98), using ksh script

Let me preface by saying, I have looked through many threads that deal with keep the decimal, however I'm not sure that any one resolution meets my needs, ok, ok, they could. So maybe it's just that I am not understanding the resolution - therefore I am posting a new thread.

myknowledgebase=at times seems pretty insufficient

system=AIX
version=5.3.0.60
script lang.=ksh

description -
I have been task with automating the calculation of server uptime.
1. I have a control that is manually updated with server downtime in
minutes.
2. I have a script that pulls out the minutes and tries to run them through
the calculation.
3. I tried to "| bc -l" at the end of my calculations, which gives errors of
improper syntax (man bc - not an easy read) find it hard to determine
what the syntax should be.
4. Never was really good with math Smilie

control file looks like -
Code:
YES::YES (see below):NO:04/14/2008:30:(IR 123454) outages caused by large number of 2000 page statement pulls::20:::120:::45:::320::

meat & potatoes -
Code:
#!/bin/ksh

exec 2>>/tmp/chad8.$$
set -x

#
#set control file to var
#

OUTINFO=/home/lehc01/tbin/apioutages

#
#set vars to type integer
#

typeset -i OUTMIN1 OUTMIN2 OUTMIN3 OUTMIN4 OUTMIN5 MNTHMINS OUTMINTOT PRCNT1 PRCNT2 PRCNT3 DAYS

#
#get minutes from control file
#

grep YES $OUTINFO | while read file
do
OUTMIN1=`echo $file | cut -d':' -f6`
OUTMIN2=`echo $file | cut -d':' -f9`
OUTMIN3=`echo $file | cut -d':' -f12`
OUTMIN4=`echo $file | cut -d':' -f15`
OUTMIN5=`echo $file | cut -d':' -f18`
done

#
#set month year
#

MNTH=02
YEAR=2008

#
#get number of days in month
#

let DAYS=`cal $MNTH $YEAR | grep . | fmt -1 | tail -1`

#
#get total minutes for the month
#

let MNTHMINS=$((1440 * DAYS))


#
#get total outage minutes
#

OUTMINTOT=0
let OUTMINTOT=$OUTMIN1+$OUTMIN2+$OUTMIN3+$OUTMIN4+$OUTMIN5
echo $OUTMINTOT

#
#calculate percentage of uptime
#

let PRCNT1=$((MNTHMINS - OUTMINTOT))
echo $PRCNT1
let PRCNT2=$((PRCNT1 / MNTHMINS))
echo $PRCNT2
let PRCNT3=$((PRCNT2 * 100))
echo $PRCNT3



exit 0

scripts output -
./calctotmin.ksh
535
41225
0
0


Need more info? Let me know, and thanks for the help.
# 2  
Old 06-20-2008
Are you trying to retain the decimal places ?
try using scale with bc

else, if you get any specific error post that
# 3  
Old 06-20-2008
changed code (fyi - not familiar with bc)

Yes I am trying to retain the decimal place to 1ooth place (i.e. 99.99)

Hope this helps.

here are the parts of code I changed.
Code:
#
#get total minutes for the month
#

MNTHMINS=$('scale = 2; 1440*DAYS' | bc)


#
#get total outage minutes
#

OUTMINTOT=0
OUTMINTOT=$('scale = 2; OUTMIN1+OUTMIN2+OUTMIN3+OUTMIN4+OUTMIN5' | bc)
echo $OUTMINTOT

#
#calculate percentage of uptime
#

PRCNT1=$('scale = 2; MNTHMINS-OUTMINTOT' | bc)
echo $PRCNT1
PRCNT2=$('scale = 2; PRCNT1/MNTHMINS' | bc)
echo $PRCNT2
PRCNT3=$('scale = 2; PRCNT2*100' | bc)
echo $PRCNT3

here is the error output -
Code:
+ + bc
+ scale = 2; 1440*DAYS
./calctotmin.ksh[48]: scale = 2; 1440*DAYS:  not found.
MNTHMINS=
+ OUTMINTOT=0
+ + scale = 2; OUTMIN1+OUTMIN2+OUTMIN3+OUTMIN4+OUTMIN5
+ bc
./calctotmin.ksh[56]: scale = 2; OUTMIN1+OUTMIN2+OUTMIN3+OUTMIN4+OUTMIN5:  not found.
OUTMINTOT=
+ echo 0
+ + scale = 2; MNTHMINS-OUTMINTOT
+ bc
./calctotmin.ksh[63]: scale = 2; MNTHMINS-OUTMINTOT:  not found.
PRCNT1=
+ echo 0
+ + bc
+ scale = 2; PRCNT1/MNTHMINS
./calctotmin.ksh[65]: scale = 2; PRCNT1/MNTHMINS:  not found.
PRCNT2=
+ echo 0
+ + bc
+ scale = 2; PRCNT2*100
./calctotmin.ksh[67]: scale = 2; PRCNT2*100:  not found.
PRCNT3=
+ echo 0
+ exit 0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

two questions about incorporating fortune and java uptime into screen for a minecraft server

existing code #!/bin/bash SRC_DIR=/home/brian/mc/ DEST_DIR=/home/brian/mcbak/ SCREEN_SESSION=minecraft BACKUP_LOG=/home/brian/mcbaklog CHKBAK=$(rdiff-backup -v3 --verify ~/mcbak) BAKSZ=$(du -sh ~/mcbak|awk 'FNR == 1 {print $1}') WLDSZ=$(du -sh ~/mc/world/|awk 'FNR == 1 {print $1}')... (1 Reply)
Discussion started by: briandanielz
1 Replies

2. Red Hat

Server uptime is showing 0hr but server not rebooted

Hi One of our server is showing the uptime 0hr 5mints there is no log in /var/log/messages there is no log in command "last" kernel version is 2.4.9 (RH2.1 AS) What could be the reason for this. is this issue is related to uptime counter reached max how to verify this. Best Regards KVK (4 Replies)
Discussion started by: venikathir
4 Replies

3. Shell Programming and Scripting

KSH script Not working (calculate days since 1/1/2000 given day 4444)

I am unable to get this KSH script to work. Can someone help. I've been told this should work with KSH93. Which I think I have on Solaris 10. If I do a grep -i version /usr/dt/bin/dtksh I get @(#)Version M-12/28/93d @(#)Version 12/28/93 @(#)Version M-12/28/93 This is correct for... (5 Replies)
Discussion started by: thibodc
5 Replies

4. Linux

uptime command output when the server is running more than one year?

What is the uptime command output when the server is running more than one year? My doubt is whether it show in number of days format or number years and number of days format? For example, Assume the server is running 400 days 3 hrs 3 min 3 secs. The output like 400 days 3:3 min or 1 year 5... (3 Replies)
Discussion started by: maruthu
3 Replies

5. Shell Programming and Scripting

Extract the uptime from the output of the uptime command

Hi! I want to extract the uptime from the output of the uptime command. The output: 11:53 up 3:02, 2 users, load averages: 0,32 0,34 0,43 I just need the "3:02" part. How can I do this? Dirk (6 Replies)
Discussion started by: Dirk Einecke
6 Replies

6. Shell Programming and Scripting

Total number of users logged in a server from uptime

how to find out total number of users logged in a server from uptime . i mean to say i need the total output of unix command . who gives the out put at a particular time . I need at all time from which machine who has connected , (3 Replies)
Discussion started by: amiya.te@gmail
3 Replies

7. Shell Programming and Scripting

ksh script not running in another directory on same server

I have a script that runs fine under my home directory. No syntax errors, runs and returns as expected. When I migrate the script to the UAT directories on the same server for User testing, I get a syntax error. I've checked to make sure the .profile I'm using is the same in the UAT... (1 Reply)
Discussion started by: mpflug
1 Replies

8. Solaris

Server uptime statistics

Hello, I would like to create a report every month about the working hours of some servers. I need to get results such as how long are the servers up every month, which hours/days are up. Do you know any tool which will help me? Thanks in advance (2 Replies)
Discussion started by: @dagio
2 Replies

9. Shell Programming and Scripting

How to call the ksh script when rebooting the server

Hi all, Can any one help me....... I just want to run one shell script whenever i am rebooting the server. Is there any easy way to do that???? Thanks, selva (7 Replies)
Discussion started by: Selva_Kumar
7 Replies

10. Shell Programming and Scripting

ksh script using expr to calculate percentages

Within a ksh script on HP-UX I trying to calculate a percentage of a number (number/100 x percentage) using the below method and expr. TARPERC=`expr 16 / 100 \* 5` TARSUM=`expr 16 + $TARPERC` ZIPSUM=`expr $TARSUM \* 2` If the input is 16 outputs are: TARPERC: 0 TARSUM: 16 ZIPSUM: 32... (6 Replies)
Discussion started by: wurzul
6 Replies
Login or Register to Ask a Question