It works really well provided that the swap is set to 1GB but I tend to forget this and if it is the standard 100M then the scripted build winds into a problem some 30 minutes later. The error message does not say it is missing swap but that is the core reason nevertheless.
So I want to complement my script at the start with a swap test followed by and error message and exit if swap is set to less than 1000 MB.
I have looked at several commands to show the swap size on screen but I don't know how to extract the actual number and then compare it to my limit and make the script branch away when it is not OK.
Any suggestions on how to create such a function?
Here are some commands I have tested to find swap size:
Code: Select all
$ cat /proc/swaps
Filename Type Size Used Priority
/var/swap file 102396 9984 -2
$ swapon -s
Filename Type Size Used Priority
/var/swap file 102396 9984 -2
$ free -h
total used free shared buff/cache available
Mem: 927M 125M 49M 12M 752M 725M
Swap: 99M 9.8M 90M
$ free
total used free shared buff/cache available
Mem: 949448 129776 48928 12736 770744 741436
Swap: 102396 9984 92412
$ free | grep Swap
Swap: 102396 9984 92412
I want to proceed only if the value is > 1000000.