Hey
i have problem with cut and print column
problem is i want to execute shell script to run df -h /tmp
if the result ( Use% ) was more than 50% , run rm -rf /tmp/*
any idea how cut the result of df -h /tmp
?
Hello nimafire,
You haven't mentioned you O.S details into your post, so code which I am providing I tested in BASH, may help you in same.
USAGE=`df -hP /tmp | awk 'FNR>1{sub(/%/,X,$(NF-1));if($5+0 > 0){print $(NF-1)}}'`
if [[ $USAGE -gt 0 ]]
then
echo "Removing the files from /tmp now...."
rm -rf /tmp/*
else
echo "/tmp have not filled more than 50% as of now."
fi
Thanks,
R. Singh