DEV Community

loading...

Discussion on: Get server stats with bash

Collapse
goodevilgenius profile image
Dan Jones

You've got a few possible improvements in here.

Here's what I found.

free -m | head -n 2 | tail -n 1 | awk {'print $4'}

# could be, like you use in CPU idle
free -m | sed -n 2p | awk '{print $4}'

# but more simply
free -m | awk 'NR == 2 {print $4}'
Enter fullscreen mode Exit fullscreen mode
free -m | tail -n 1 | awk {'print $3'}

# like you do with free space
free -m | awk 'END {print $3}'
Enter fullscreen mode Exit fullscreen mode
df -h / | awk '{ a = $4 } END { print a }'

# You don't need to store a variable here
df -h / | awk 'END { print $4 }'
Enter fullscreen mode Exit fullscreen mode
Collapse
decentralizuj profile image
decentralizuj Author

Thanks on pointing that out, I'll edit script with your improvements.