Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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`"
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.