Computer Science, asked by pappukumar4350, 1 year ago

Write a script in linux that prints a summary of the disk space usage

Answers

Answered by Anonymous
25
ANSWER

...................



               #DSAlert.sh
                                                              #!/bin/sh




#Retrive disk space info


df=`df -Pl  |


 grep "^/dev" |

 awk


'{print

$5, $6}' |


 sed "s/%//"`


#Reference: df


echo “$df” | while read percent fs
do


#If Disk Usage increases above 90% send an email.


if [ $percent -ge 90 ] ; then


#Calling a perl file with parameters for sending an emai
l.



`/opt/lampp/bin/perl DiskSpace_Alert.pl $fs is $percent percent full`
fi


done


NOW



# DiskSpace_Alert.pl
#!perl
use MIME::Lite;

#Reference : Mime-Lite

# set up email
$to = “my-mail-id\@domain.com”;
$from = “Diskmonitor\@ServerName.com”;
$subject = “Disk_Alert”;
$message = “Disk Space issue.\nActions Required:\n”.”@ARGV”;
# send email
email($to, $from, $subject, $message, $file);

# email function
sub email
{
# get incoming parameters
local ($to, $from, $subject, $message, $file) = @_;
# create a new message
$msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Data => $message);
# send the email

MIME::Lite->send(‘smtp’, ‘localhost’, Timeout => 60);
$msg->send();
}




Similar questions