LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-27-2020, 12:13 PM   #1
venugosr
LQ Newbie
 
Registered: Apr 2015
Posts: 22

Rep: Reputation: Disabled
Disk Utilization


Hi Team,

I have a script which will help me to find if the FS is reaches 90%

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
But I have one more command which will help to find the file occupying more space.

Code:
find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head
The problem is I dont know how to use this above code in the main script.

My goal is whenever the File System reached the maximum limit then it should send an email with file names which is occupying more space.

Please help me on this.

Last edited by venugosr; 07-27-2020 at 12:14 PM.
 
Old 07-27-2020, 12:19 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,650

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by venugosr View Post
Hi Team,
I have a script which will help me to find if the FS is reaches 90%
Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
But I have one more command which will help to find the file occupying more space.
Code:
find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head
The problem is I dont know how to use this above code in the main script. My goal is whenever the File System reached the maximum limit then it should send an email with file names which is occupying more space.
As you've been told before, we are NOT on your 'team'...we don't work with you, nor are we tech support. Your question doesn't seem to make much sense, as written...you're saying you wrote a script, but somehow don't know how to add one more line to it??? You're already using the df command in your script, so why is it a problem to add the line you already HAVE, in the same manner??

What difficulties are you having?? Seems like you've written a script, have the command you want to run, and already KNOW how to use commands as variables....where are you stuck?? You've been using Linux for at least five years now...adding a single line to a shell-script seems like something you can already do.
 
Old 07-27-2020, 12:34 PM   #3
venugosr
LQ Newbie
 
Registered: Apr 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
Hello,

I have tried all the possible ways, but not getting the output in the mail, that's why i asked help here.
I am not expert in scripting like you, if you are willing help then please do that. Else leave it.

Thanks for your reply..
 
Old 07-27-2020, 12:46 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,650

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by venugosr View Post
Hello,
I have tried all the possible ways, but not getting the output in the mail, that's why i asked help here. I am not expert in scripting like you, if you are willing help then please do that. Else leave it.
Glad to help; so why don't you post these 'all possible ways' you've tried??? Can you show us ANY of the ways you've tried already??? The email you got when you tried? ANYTHING? Read the "Question Guidelines" link in my posting signature.

Again, seems very odd that you have five years experience with scripting/Linux, you wrote a script but are unable to add a single line to it, especially when that script has examples of EXACTLY what you need to do in it already.
This seems to be a common thread with your posts, where you just ask others to do things for you:
https://www.linuxquestions.org/quest...ml#post6102489
https://www.linuxquestions.org/quest...lc-4175571722/
https://www.linuxquestions.org/quest...on-4175538922/

Last edited by TB0ne; 07-27-2020 at 12:51 PM.
 
Old 07-27-2020, 12:56 PM   #5
venugosr
LQ Newbie
 
Registered: Apr 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
Hello,

I have tried the below ways, but the output not coming in the mail.

First Method

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}|\n ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
Second Method

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}"|\n " ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
Third Method

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}"|"\n ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
 
Old 07-27-2020, 01:10 PM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,650

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by venugosr View Post
Hello,
I have tried the below ways, but the output not coming in the mail.
First Method
Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}|\n ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
Second Method

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}"|\n " ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
Third Method

Code:
#!/bin/bash
echo "Start date and Time `date +%Y-%m-%d-%T`"
Date=`date +%Y-%m-%d-%T`
MAXvalue="90"
MailList="emailaddress"
FSUsage=`df -h /opt | awk -F " " '{print $5}' | tail -n 1 | tr -d '%'`
if [ "${FSUsage}" -ge "${MAXvalue}" ]
then
FNAME=`find /opt -xdev -type f -ls | awk '{print $7" "$11}' | sort -rn | head`
echo "Hi Team, OPT file system in INT region exceed to ${FSUsage}%. Please take necessary action. Alert triggered on ${Date}"|"\n ${FNAME}" | mail -s "OPT FS exceeds ${FSUsage}% than threshold in `hostname`" ${MailList}
fi
echo "End date and Time `date +%Y-%m-%d-%T`"
...and as asked before, what does the email actually SAY??? What are you getting for the FNAME variable?? Because the first effort you posted works fine for me, and echos the proper values to the screen.
 
Old 07-27-2020, 01:15 PM   #7
venugosr
LQ Newbie
 
Registered: Apr 2015
Posts: 22

Original Poster
Rep: Reputation: Disabled
From FNAME i will get the list of files which is occupying more space.
In the email I want to list out the file names which is occupying more space in the subject.
 
Old 07-27-2020, 01:17 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,650

Rep: Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970Reputation: 7970
Quote:
Originally Posted by venugosr View Post
From FNAME i will get the list of files which is occupying more space. In the email I want to list out the file names which is occupying more space in the subject.
Right; that's what you said initially. AGAIN...you say it's not coming through in the email, and you're being asked to SHOW US THE EMAIL and tell us what you ARE getting from what you've done. We can't guess. Again: suggest you echo the variable to the screen and post that, along with the email you're getting.

As said, the first sample you posted works fine for me.
 
Old 07-31-2020, 10:58 AM   #9
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,803

Rep: Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202Reputation: 1202
The best method is a (sub shell)
Code:
(
echo ...
find ...
) | mail ...
You can also use a {code group;}
Code:
{
echo ...
find ...
} | mail ...
and due to the pipe the shell will automatically make a sub shell.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
High Run queue utilization although CPU utilization is low.. rajeprag Linux - Server 0 08-18-2013 09:44 AM
Sending alert if CPU or RAM or Disk reaches 90% utilization dhanju Linux - Server 2 08-18-2008 10:07 AM
Hard Disk utilization gyropk Linux - Hardware 1 07-08-2008 01:15 PM
Linux desktop GUI tool for CPU utilization and bandwidth utilization karimasif Linux - Software 4 03-03-2008 01:09 PM
disk/processsor utilization oscillation tbirch Linux - General 1 06-20-2003 09:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration