#!/bin/sh ## ## SCRIPT NAME: get_memory_and_swap.sh ## ############################################################################# ## PURPOSE: ## Gets 'memory' and 'swap' data from output of the 'free' command. ## ## Example output from the 'free -m -o' command: ## ## total used free shared buffers cached ## Mem: 3275 595 2679 0 114 243 ## Swap: 2290 0 2290 ## ## where '-m' means the data is shown in megabytes instead of the default of ## kilobytes --- and '-o' means that a line of buffer/cache data is not shown. ## ## This script gets the data from the 'total' and 'used' columns. ## ############################################################################# ## CALLED BY: a Tk GUI script that shows 'memory' and 'swap' data ## as needle readings on a couple of meters (dials) drawn ## on a Tk canvas --- Tk script name: ## meters_memory_swap.tk ## ############################################################################# ## MAINTENANCE HISTORY: ## Updated by: Blaise Montandon 2013aug08 Started this script on Linux, ## using Ubuntu 9.10 (2009 October, ## 'Karmic Koala'). ## Updated by: Blaise Montandon 20....... ############################################################################# ## FOR TESTING: # set -x # FREEOUT=`free -m -o | tail -2 | cut -c6-30 | tr '\n' ' ' | sed 's/ */ /g'` free -m -o | tail -2 | cut -c6-30 | tr '\n' ' ' | sed 's/ */ /g'