Skip to content

Division through zero #4

@yvesh

Description

@yvesh

If you don't have any swap / your swap is zero byte you get an division by zero error ($2)

free -b | awk '$ 1 == "Swap:" {total=$ 2; used=$ 3; free=$ 4; pfree=($ 4*100/$ 2); pused=($ 3*100/$ 2); if("$1" == "") {printf("%.0f", free )} else {printf("%.0f", $1 "" )} }'

awk: cmd. line:1: (FILENAME=- FNR=3) fatal: division by zero attempted
free -h
              total        used        free      shared  buff/cache   available
Mem:            ....
Swap:            0B          0B          0B

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions