Results 1 to 3 of 3
Hello,
I am trying to create a script to be used on RHEL server. If I replace the $t with a number, the script works. If I try add a ...
- 07-09-2010 #1Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
Help with script with variable in if statement
Hello,
I am trying to create a script to be used on RHEL server. If I replace the $t with a number, the script works. If I try add a variable or the $1, the script doesn’t work (returns all processes even if less than the $t value). I thought that it may be treating it as a literal, but I wasn’t sure of the conversion.
t=$1
echo $t
lcnt=`ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid | awk '{if ($6 > $t) print $1 " "$5 " "$6 " " $7}' | wc -l`
#echo $lcnt
if test $lcnt -eq 0 ; then echo "0 0.0 0.0 null" ; else ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid | awk '{if ($6 > $t) print $1 " "$5 " "$6 " " $7}' ; fi
Thanks in advance for any assistance.
Brian
- 07-10-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 452
welcome to the forum
try exposing the "$t" in your awk script--
awk '{if ($6 > '$t')...
do it both places so the shell can make appropriate substitutionthe sun is new every day (heraclitus)
- 07-12-2010 #3Just Joined!
- Join Date
- Jul 2010
- Posts
- 2
Thank you. Using the '$t' is working and returning the proper output.


Reply With Quote