hint: [user@server ~]# free [user@server -] # TOTAL_MEMORY=$( free | grep Mem: | awk '{print $2}') [user@server -]# echo
Posted: Fri May 20, 2022 11:38 am
[email protected] bash$ ./memory_check -e [email protected] -w 60 -c 90 • hint getopts The sample invocations will return warning if memory usage is greater than or equal to 60% or total memory (but less than 90%). if usage is greater than 90%, it will return critical (and will use the email address to send more info - see Bonus below) If no parameters were supplied, script should tell the user the required parameters o script must ensure that critical threshold is always greater than the warning threshold, otherwise, print the required parameters 2. the script will exit with the following values o 2: used memory is greater than or equal to critical threshold o 1: used memory is greater than or equal to warning threshold but less than the critical threshold o 0:used memory is less than warning threshold o hint: exit 3. [Bonus] if used memory is greater than or equal to critical threshold, the script must send the top 10 processes (with process ids) that use a lot of memory to the specified email address o subject of the email must be in this format: "YYYYMMDD HH:MM memory check - critical" YYYYMMDD HH:MM - year, month date, hour minute (e.g. 20140801 22:16)
hint: [user@server ~]# free [user@server -] # TOTAL_MEMORY=$( free | grep Mem: | awk '{print $2}') [user@server -]# echo $TOTAL_MEMORY script name: memory_check 0 1. create a bash script that will check memory usage. It requires 3 parameters -c: critical threshold (percentage) o-W: warning threshold (percentage) e: email address to send the report (see Bonus below) NOTE: the parameters must not be positional. Sample invocation: bash$ ./memory_check -c 90 - 60 -e