Need little script to send out email


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need little script to send out email
# 1  
Old 06-14-2017
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
# 2  
Old 06-14-2017
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".
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-14-2017
Quote:
Originally Posted by jaapar
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:
Mod Comment 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.
This User Gave Thanks to lightman66 For This Post:
# 4  
Old 06-15-2017
Quote:
Originally Posted by lightman66
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:
Mod Comment 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>

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to send email if count is >1

i have below code to count number of rows in file1.txt, if the row count is more than one then i have sending an email along with file1.txt attached and fail the process(do nothing if count is <=1), if I test individually count part works good but when i include the email part its not working,... (4 Replies)
Discussion started by: srini_106
4 Replies

2. Shell Programming and Scripting

Help....script check status if see something then send email

autorep -m bogus Machine Name Max Load Current Load Factor O/S Status ___________ ________ ___________ ______ ________ ______ bogus --- --- 1.00 Sys Agent Online Status ______ Online Offline Missing Unqualified The "Status" always "Online". I like create a script execute run... (6 Replies)
Discussion started by: dotran
6 Replies

3. Shell Programming and Scripting

Script to Send an email using mail command

Hello all I'm trying to write a script to send an email, so I can be nnotified when something is going wrong with my system. I've tried many options with no luck: mail -s "You've got mail" somebody@example.com echo "Mail Body" | mail -s "Subject" somebody@example.com I tried also to... (1 Reply)
Discussion started by: samer.odeh
1 Replies

4. Shell Programming and Scripting

Help with shell script to send email once

Hi Guys, I have this script which will monitor oracle db process if up or down.And I want it to send email if it's down and the time it's back to online. However my script just keep on sending "Email Up" if the db is up or "Email Down" if the db is down.Is there any way to trap it so that it... (5 Replies)
Discussion started by: d3xt3r
5 Replies

5. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

6. Shell Programming and Scripting

How to send email through shell script

Hi All, I am new to the unix , i have to deliver one script very urgently I have to write a shell script where i have i want to send email to specific email id in this script i want FROM to be parameterized and stored in a variable TO to be parameterized and stored in a variable... (3 Replies)
Discussion started by: nileshbhawsar
3 Replies

7. Shell Programming and Scripting

send an email of script output

Hi All, I'm trying to send some file which generated by script to my email. when I run the script I'm getting an email. Thats fine. But it seems to be all messed up like below Memory Status on ServerA: Mem: 3867444k total, 862680k used, 3004764k free, 54456k buffers!! CPU Status on ServerA:... (4 Replies)
Discussion started by: s_linux
4 Replies

8. Shell Programming and Scripting

Send email on script error

I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble. I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron. #!/bin/sh PGPPATH=/path/to/directory echo "pgp... (6 Replies)
Discussion started by: Aslan_Eident
6 Replies

9. Shell Programming and Scripting

script to send a file in email

a file is created on a daily basis in the name xyz_pqr_20071207.dat.i want to send the file as an attachment if the file contains more than 50 records.how can i write a script such that it will transmit the file after the file is created.i want to sed the file to say asdf@xyz.com. please help me... (2 Replies)
Discussion started by: dr46014
2 Replies

10. Shell Programming and Scripting

script that will send and email attachment

I'm looking for a sample of some code that will take the output from a file and generate an email that will include that text as an attachment. the script is in the borne shell. any help? (2 Replies)
Discussion started by: davels
2 Replies
Login or Register to Ask a Question