Skip to main content
improved formatting, removed thanks, improved title
Source Link

(Bash) Bash: kill process according toin function of the memory used

i makeI made this script to close a process, but iI can't compare a output awkthe awk result (var1var1) with a integeran Integer: var1 -gt 5000.

the problem is casting in bash?My script:

#!/bin/bash

var1= free -m |awk 'NR == 2'| awk '{print $3}'
var2= ps aux | grep '/opt/skype/skype' | grep -v grep | awk '{print $2}'

while true;
do
     if [ $var1 -gt 5000 ]; then
         echo "La memoria se ha excedido cerrando porcesos"
         kill -9 $var2
     break
     else
     echo "La memoria aun es estable $var1"
     fi
done

thanksCould it be a casting problem in bash?

(Bash) kill process according to the memory used

i make this script to close a process, but i can't compare a output awk (var1) with a integer.

the problem is casting in bash?

#!/bin/bash

var1= free -m |awk 'NR == 2'| awk '{print $3}'
var2= ps aux | grep '/opt/skype/skype' | grep -v grep | awk '{print $2}'

while true;
do
     if [ $var1 -gt 5000 ]; then
         echo "La memoria se ha excedido cerrando porcesos"
         kill -9 $var2
     break
     else
     echo "La memoria aun es estable $var1"
     fi
done

thanks

Bash: kill process in function of the memory used

I made this script to close a process, but I can't compare the awk result (var1) with an Integer: var1 -gt 5000.

My script:

#!/bin/bash

var1= free -m |awk 'NR == 2'| awk '{print $3}'
var2= ps aux | grep '/opt/skype/skype' | grep -v grep | awk '{print $2}'

while true;
do
     if [ $var1 -gt 5000 ]; then
         echo "La memoria se ha excedido cerrando porcesos"
         kill -9 $var2
     break
     else
     echo "La memoria aun es estable $var1"
     fi
done

Could it be a casting problem in bash?

Source Link
ymk369
  • 133
  • 2
  • 14

(Bash) kill process according to the memory used

i make this script to close a process, but i can't compare a output awk (var1) with a integer.

the problem is casting in bash?

#!/bin/bash

var1= free -m |awk 'NR == 2'| awk '{print $3}'
var2= ps aux | grep '/opt/skype/skype' | grep -v grep | awk '{print $2}'

while true;
do
     if [ $var1 -gt 5000 ]; then
         echo "La memoria se ha excedido cerrando porcesos"
         kill -9 $var2
     break
     else
     echo "La memoria aun es estable $var1"
     fi
done

thanks