Reputation: 579
Code below is supposed to check the memory for user and if its greater than 1000, print message I keep getting error- line 4: impala: command not found
#!/bin/bash
while [ true ] ;do
used= `ps hax -o rss,user | awk '{a[$2]+=$1;}END{for(i in a)print i"
"int(a[i]/1024+0.5);}' | grep user`
if [[ $used > 1000 ]]; then
echo "user memory is $used"
fi
sleep 5
done
I have tried used= ps hax -o rss,user | awk '{a[$2]+=$1;}END{for(i in a)print i" "int(a[i]/1024+0.5);} | grep user'
and used= 'ps hax -o rss,user | awk '{a[$2]+=$1;}END{for(i in a)print i" "int(a[i]/1024+0.5);}' | grep user'
I need a fresh eye on this. Please help.
Upvotes: 0
Views: 86
Reputation: 21965
In bash, as mentioned [ here ], putting spaces around the equal sign would cause errors, So the right format is
variable_name=value;
Moreover, you may change
while [ true ]
to
while true
Edit
If used
has the form impala 600
and you're only interested in the number at the end, then you may do
used="${used##* }"
#Do this just after the your first command.
Finally do
#use -gt for integer comparisons and > for string comparisons
if ! [ -t $used ] && [ $used -gt 1000 ]
then
echo "user memory is $used"
fi
Note: Though the syntax errors in the script is resolved there is no guarantee that the program logic is right
Upvotes: 1