Sponsored Content
Top Forums Shell Programming and Scripting calculate server uptime in % (99.98), using ksh script Post 302207717 by cml2008 on Friday 20th of June 2008 03:05:37 PM
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

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
svm-scale(1)							   User Manuals 						      svm-scale(1)

NAME
svm-scale - scale data to a restricted range as preprocessing for SVM training SYNOPSIS
svm-scale [ -l lower ] [ -u upper ] [ -y y_upper ] [ -s save_filename ] [ -r restore_filename ] datafilename DESCRIPTION
svm-scale reads the given datafilename (a training or testing data file as specified in svm_train(1) or svm_predict(1) ) and scales all dimensions to the given ranges. OPTIONS
-l lower lower is the lowest (minimal) value allowed in each dimension. It defaults to -1. -u upper upper is the highest (maximal) value allowed in each dimension. It defaults to 1. -y y_lower y_lower is a boolean value (0 or 1) indicating whether or not y-values (targets) should be scaled. It defaults to 0. -s save_filename save_filename indicates the filename to save the scaled data to. -r restore_filename restore_filename indicates the filename reserved to hold the original (unscaled) data in case there is a need to restore. FILES
datafilename must be a training or testing dataset. ENVIRONMENT
No environment variables. DIAGNOSTICS
None documented; see Vapnik et al. BUGS
Please report bugs to the Debian BTS. AUTHOR
Chih-Chung Chang, Chih-Jen Lin <cjlin@csie.ntu.edu.tw>, Chen-Tse Tsai <ctse.tsai@gmail.com> (packaging) SEE ALSO
svm-train(1), svm-predict(1) Linux MAY 2006 svm-scale(1)
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy