Using the class notes, text book, web sites, etc. write a script that shows you
ID: 3602409 • Letter: U
Question
Using the class notes, text book, web sites, etc. write a script that shows you available CPU, Memory and Disk space.
In other words by running a command like ./my you should get the information requested above
Please provide me your source code in a .doc or .docx format. Also be sure to insert a snap shot (picture) on the bottom of your source code showing that you ran the script and obtained its result.
About 20% of your answer can be copied from resources (books, web site, etc.). If so, please be sure to put that into quotation form, also indicate foot notes and provide the resource(s) for anything you copy.
Explanation / Answer
The script using for memory check is
free -m | awk 'NR==2{printf "%.2f%% ", $3*100/$2 }'
for disk :
df -h | awk '$NF=="/"{printf "%s ", $5}'
for cpu
top -bn1 | grep load | awk '{printf "%.2f%% ", $(NF-2)}'
the above mentioned was the basic parts of the script need to save this commands into variables
we need the script to run for certain amount of time using while do loop
end=$((SECONDS+7200))
while [ $SECONDS -lt $end ]; do
echo "$MEMORY$DISK$CPU"
sleep 5
done
inorder a run a loop at certain time we are using end an hour it consists of 3600 seconds so it runs every 2 hours .inside this loop these variables are assigned every 10 seconds
Here Is the complete code
printf "Memory Disk CPU "
end=$((SECONDS+3600))
while [ $SECONDS -lt $end ]; do
MEMORY=$(free -m | awk 'NR==2{printf "%.2f%% ", $3*100/$2 }')
DISK=$(df -h | awk '$NF=="/"{printf "%s ", $5}')
CPU=$(top -bn1 | grep load | awk '{printf "%.2f%% ", $(NF-2)}')
echo "$MEMORY$DISK$CPU"
sleep 5
done
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.