The Rock
asked on
need a help to fix one if else shell script issue
I need a specific function just to calculate swap size as per ram like:
if ram < 2048 then swap should be 1.5 times
if ram > 2048 and ram < 16536 then swap size should be equal to ram
if ram > 16536 then swap size should be 16536
please help
if ram < 2048 then swap should be 1.5 times
if ram > 2048 and ram < 16536 then swap size should be equal to ram
if ram > 16536 then swap size should be 16536
please help
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Chris and Sharath - Both approach looks fine with me only one thing left like if i take Sharath sample code below:
#!/bin/bash
ram=103
if [ $ram -gt 16536 ]; then
swap=16536
elif [ [$ram -gt 2048] && [$ram -lt 16536] ]; then ---- This line gives me issues - i know i am doing something stupid but unable to find - please help
swap=$ram
else
swap=$(echo "$ram*1.5" | bc)
fi
echo -e "swap value: $swap"
#!/bin/bash
ram=103
if [ $ram -gt 16536 ]; then
swap=16536
elif [ [$ram -gt 2048] && [$ram -lt 16536] ]; then ---- This line gives me issues - i know i am doing something stupid but unable to find - please help
swap=$ram
else
swap=$(echo "$ram*1.5" | bc)
fi
echo -e "swap value: $swap"
You don't need to check if the value is less than 16536. because it reaches 2nd else only if the first condition fails. i.e. if ram less than 16536.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Sharath for your quick help really appreciated.
Thanks Chris too for your quick and alternative for the solution. It helps me too.
Thanks Chris too for your quick and alternative for the solution. It helps me too.
Open in new window