Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sleep command and figure percentage in a script

Status
Not open for further replies.

squash

MIS
May 21, 2001
99
US
Hello a couple of quick and hopefully simple questions.

1. Is there any way to use the sleep command for less than one second time interval? i.e.
while :
do
echo “1”
sleep .5
done
2. What might be an easy way to figure out a percentage in a script.
For example I know how to capture a number for a specific count and this will rise and fall all day, I am only concerned if it jumps by say 20%.

So an example might be

MQ=`netstat –n |grep 59100|wc –l
A=`cat fileone`
B=`cat filetwo`

while :
do
$MQ >fileone
sleep 600
$MQ>filetwo

# Ok this is where I am guessing.

let C=$B-$A
let D=$C/$A

if [ $D –gt 20 ]
then
beep me
else
sleep 3600
fi
done

As Alway we thank you for your support.
 
echo "scale=2; ((${B} - ${A}) / ${B}) * 100" | bc vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Ok,
It took some playing with my variables, but I got it to work just fine.

So arithmatic functions just happen I guess?
Or I guess a better questions is can you break down what is happening for me.

What is scale?

Thankx for you help all the same

 
you need floating number operation to calculate percentage.
Shells [mostly] don't support that. Therefore you need to use 'bc'.

From 'man bc':
scale ( E )
Number of digits right of decimal point.


By default scale=0 which makes all operations interger.
The rest of the expression is the percentage calculation given your formula from the original post [if I understood it correctly].
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
right on I get that, and yes you did understand my orig post correctly.

I guess I just have not seen the use of the echo command as in your statement.

Althought it works great.

Thankx again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top