hint: [user@server ~]# free [user@server -] # TOTAL_MEMORY=$( free | grep Mem: | awk '{print $2}') [user@server -]# echo

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

hint: [user@server ~]# free [user@server -] # TOTAL_MEMORY=$( free | grep Mem: | awk '{print $2}') [user@server -]# echo

Post by answerhappygod »

Hint User Server Free User Server Total Memory Free Grep Mem Awk Print 2 User Server Echo 1
Hint User Server Free User Server Total Memory Free Grep Mem Awk Print 2 User Server Echo 1 (49.35 KiB) Viewed 29 times
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 [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)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply