#!/bin/bash # -----------------------------------------------------------------------------------# # Set variables from commandline argument values # -----------------------------------------------------------------------------------# while getopts "g:" opt; do case $opt in g) # Show grep results for primary system components grepVal=$OPTARG ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 ;; esac done echo "-- Processes using more than 0% Memory" echo -e 'Date\t\t\tMem%\t#procs\tApplication' ps aux | awk '{print $4"\t"$11"\t"$16}' | sort | uniq -c | awk '{if($2>0) print d"\t"$2"\t"$1"\t"$3"\t"$4}' d="$(date +'%m/%d/%Y %H:%M:%S')" | sort -nr echo "-- free -m" free -m if [ ! -z $grepVal ]; then echo -e "\n\npsgrep $grepVal --------------------------------------------------" psgrep "$grepVal" fi