kinglion580 / syl_linux

Thinking on the challenge of Linux operation and maintenance
0 stars 0 forks source link

awk #3

Open kinglion580 opened 6 years ago

kinglion580 commented 6 years ago
awk 'BEGIN{
    OFMT="%.3f";
    devf="/proc/net/dev";
    while(("cat "devf) | getline)
    {
        if($0 ~ /:/ && ($10+0) > 0)
        {
            split($1,tarr,":");
            net[tarr[1]]=$10+tarr[2];
            print tarr[1],$10+tarr[2];
        }
    }
    //close(devf);
}
function convert(flow,conver){
    k=1024
    m=1024^2
    g=1024^3
    if(flow>=k&&flow<m){
        flow=flow/k
        conver="KB"
    }
    else if(flow>=m&&flow<g){
        flow=flow/m
        conver="MB"
    }
    else
        flow=flow/g
        conver="GB"
    return flow conver
}
'