Skip to content

Instantly share code, notes, and snippets.

@fanyeren
Created March 7, 2016 08:13
Show Gist options
  • Save fanyeren/d290ebbc62d234e393c6 to your computer and use it in GitHub Desktop.
Save fanyeren/d290ebbc62d234e393c6 to your computer and use it in GitHub Desktop.
linux 空闲率计算
#!/bin/bash
cc=$(grep -c processor /proc/cpuinfo)
uptime=$(cat /proc/uptime | awk '{print $1}')
idletime=$(cat /proc/uptime | awk '{print $2}')
idle_ratio=$(echo $cc $uptime $idletime | perl -ne '{my @input = split(/\s+/, $_); my $idle = $input[2] / ($input[0] * $input[1]); print $idle, "\n";}')
idle_ratio=$(printf "%.04s" $idle_ratio)
echo -e "\t\t\t\t\t\e[1;31m开机以来空闲率:$idle_ratio\e[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment