Why this python script is giving wrong output,using awk and comapring value in if block?
<p>I want to get desktop notification whenever load is more than  five,for that I have written this python script but it is giving opposite to expected</p>

<pre><code>#!/usr/bin/python
import commands

a=commands.getoutput("cat /proc/loadavg | awk '{print $1}'")
float (a)
print a
if (a &gt; 5.00):
    commands.getoutput('notify-send "Hello world!" ')
else:
    print "load looks fine!!"
</code></pre>

<p>Can someone rectify this ?</p>

<p>You need to assign the typecast float value back to <code>a</code>. A plain print to console can be deceiving since you will not be able to tell if the variable is a float or not. So you can use <code>type</code> to confirm</p>

<pre><code>#!/usr/bin/python
import commands

a = commands.getoutput("cat /proc/loadavg | awk '{print $1}'")
a = float(a) # assign back to a
print a, type(a)
if a &gt; 5.00:
    commands.getoutput('notify-send "Hello world!" ')
else:
    print "load looks fine!!"
</code></pre>

python linux shell if-statement