Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Update the script and add the logic to detect and warn the user if the disk usag

ID: 3934478 • Letter: U

Question

Update the script and add the logic to detect and warn the user if the disk usage is above 80%

#! /bin/bash

LOGFILE="diskusage.log"

if [[ -n $1 ]]
then
   $LOGFILE=$1
fi

if [ ! -e $LOGFILE ]

then

   printf "%-10s %-14s %-10s %-6s %-6s %-6s %-6s " "Date" "IP Address" "Device" "Capacity" "Used" "Free" "Percentage" > $LOGFILE
fi

IP_LIST="10.10.10.2"
(
for ip in $IP_LIST;
do
   ssh client@$ip 'df -H' | grep ^/dev/ > /tmp/$$.df
   while read line;   
   do
   cur_date=$(date +%D)
   printf "%-10s %-14s" $cur_date $ip
   echo $line | awk '{ printf( "%-10s %-6s %-6s %-6s %-6s ", $1,$2,$3,$4,$5);}'
   done < /tmp/$$.df
done
) >> $LOGFILE

Explanation / Answer

*******************************************Script************************************************

#! /bin/bash


dt=`date +%D`

df -h > /tmp/$$.df
  
LOGFILE="diskusage.log"
if [[ -n $1 ]]
then
$LOGFILE=$1
fi
if [ ! -e $LOGFILE ]
then
printf "%-10s %-14s %-10s %-6s %-6s %-6s %-6s " "Date" "IP Address" "Device" "Capacity" "Used" "Free" "Percentage" > $LOGFILE
fi
IP_LIST="10.10.10.2"
(
for ip in $IP_LIST;
do
ssh client@$ip 'df -H' | grep ^/dev/ > /tmp/$$.df
while read line;   
do
//cur_date=$(date +%D)
printf "%-10s %-14s" $dt $ip

//code which is responsible to detect disk uses 80%+

echo -n "$dt $line ";;
echo -n "$dt "
echo $line | awk '{print $4}';;
echo -n "$dt "
echo $line | awk '{print $1,$5}';;
done < /tmp/$$.df
done
) >> $LOGFILE

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote