Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Need little script to send out email

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-14-2017   -   Original Discussion by jaapar
jaapar jaapar is offline
Registered User
 
Join Date: Jul 2010
Last Activity: 25 October 2017, 2:41 PM EDT
Posts: 23
Thanks: 10
Thanked 0 Times in 0 Posts
Need little script to send out email

Hi Scripters, good day.

Code:
bash-4.2# df -g /apps/prd
Filesystem      GB  blocks Free  %Used    Iused  %Iused Mounted on
/dev/xxx     64.00         4.35    94%  1269284      8% /xxx
bash-4.2#

I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be sent to a specific mailbox? Thanks in advance.

Last edited by Chubler_XL; 06-14-2017 at 05:00 PM.. Reason: Added CODE tags
Sponsored Links
    #2  
Old Unix and Linux 06-14-2017   -   Original Discussion by jaapar
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 1:17 PM EST
Location: Aachen, Germany
Posts: 11,652
Thanks: 323
Thanked 3,620 Times in 3,325 Posts
Almost certainly, yes. Look into the links at the lower left of this page, under "More UNIX and Linux Forum Topics You Might Find Helpful", or search these fora for "almost full".
The Following User Says Thank You to RudiC For This Useful Post:
jaapar (06-14-2017)
Sponsored Links
    #3  
Old Unix and Linux 06-14-2017   -   Original Discussion by jaapar
lightman66 lightman66 is offline
Registered User
 
Join Date: Mar 2017
Last Activity: 12 July 2017, 4:46 AM EDT
Posts: 2
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by jaapar View Post
Hi Scripters, good day.

Code:
bash-4.2# df -g /apps/prd
Filesystem      GB  blocks Free  %Used    Iused  %Iused Mounted on
/dev/xxx     64.00         4.35    94%  1269284      8% /xxx
bash-4.2#

I was wondering if there is a script when the usage of the mountpoint above hit 98%, email would be sent to a specific mailbox? Thanks in advance.
I think you can just set a cronjob to run at your preferred interval.

mine is running on solaris 10 hence command might varies.


Code:
20 * * * * df -h | tail +2 | awk '{if ((length($5) > 3) || ((length($5) > 2) && ($5 > 98))) print $0}' | mailx -s "Email Subject" <email address>

Moderator's Comments:
Need little script to send out email edit by bakunin: please use CODE-tags. Thank you.

Last edited by Don Cragun; 06-15-2017 at 03:38 AM.. Reason: Remove accidental edit.
The Following User Says Thank You to lightman66 For This Useful Post:
jaapar (06-15-2017)
    #4  
Old Unix and Linux 06-15-2017   -   Original Discussion by jaapar
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is online now Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 23 November 2017, 1:28 PM EST
Location: San Jose, CA, USA
Posts: 10,677
Thanks: 573
Thanked 3,738 Times in 3,190 Posts
Quote:
Originally Posted by lightman66 View Post
I think you can just set a cronjob to run at your preferred interval.

mine is running on solaris 10 hence command might varies.


Code:
20 * * * * df -h | tail +2 | awk '{if ((length($5) > 3) || ((length($5) > 2) && ($5 > 98))) print $0}' | mailx -s "Email Subject" <email address>

Moderator's Comments:
Need little script to send out email edit by bakunin: please use CODE-tags. Thank you.
You should be able to simplify that awk code a little bit to just:

Code:
20 * * * * df -h | tail +2 | awk '($5 + 0) > 98' | mailx -s "Email Subject" <email address>

but on a Solaris/SunOS system, that would be:

Code:
20 * * * * df -h | tail +2 | nawk '($5 + 0) > 98' | mailx -s "Email Subject" <email address>

The Following User Says Thank You to Don Cragun For This Useful Post:
jaapar (08-15-2017)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script that will send an email if the cron job did not run. kenshinhimura Shell Programming and Scripting 4 03-23-2017 03:57 PM
Help with shell script to send email once d3xt3r Shell Programming and Scripting 5 08-08-2011 02:46 AM
Script to send email after comparing the folder permissions to a certain permission & send email nairshar Shell Programming and Scripting 2 12-07-2010 09:22 PM
How to send email through shell script nileshbhawsar Shell Programming and Scripting 3 11-01-2010 02:30 PM
script to send a file in email dr46014 Shell Programming and Scripting 2 12-10-2007 08:38 AM



All times are GMT -4. The time now is 02:31 PM.