##Google Analz## ##Microsoft## ##Googel## Swanand: April 2015

Friday, 10 April 2015

Email alert on disk space outage in linux/vicidial/goautodial server

starbitinvest
Email alert when hard disk is full in linux



           Most of times i will be facing mysql database crash error due to my hard disk out of space , Because of huge call Recordings in vicidial or goautodial server.

so i decided to have a alert via email when my harddisk space reaches 90% .
Below is the script i used to get email alert when my hard disk reaches 90% full
thanks to : http://www.cyberciti.biz/

*******************************
Step 1: Create a bash script file
*******************************
vi /usr/share/diskspacealert.sh

*******************************
Step 2 : paste the below script
*******************************

#!/bin/sh
# refered http://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
# enter your mailed below for email alert
ADMIN="admin123@gmail.com"
# set alert level 90% is default
ALERT=90
df -HP | grep -vE '^Filesystem|tmpfs|cdrom' |
  while read partition size used free perc mnt ;
  do
    usep=$(echo $perc | tr -d '%' )
    if [ $usep -ge $ALERT ]; then
      echo "Running out of space \"$partition ($usep%)\" on $(hostname) as
  on $(date)" |
       mail -s "Alert: Almost out of disk space - $usep%" $ADMIN
    fi
  done


Note *** change the admin123@gmail.com  to your mail id to which you want email alert

*******************************
Step 3 : make the script executable
*******************************
chmod 755 /usr/share/diskspacealert.sh


*******************************
Step 4 : scheduling the scrip to run every day 
*******************************
Setpup a cronjob daily morning or whatever time you wish check the below link for cronjob turorial
http://swanand18.blogspot.in/2015/04/cronjob-tutorial-how-to-cronjob.html

type  crontab -e  in the linux shell

then add the below line

0 10 * * * /usr/share/diskspacealert.sh

this will run the script every day 10 am

Note : ***
you must have installed and configured 
Sendmail  
mailx

cronjob tutorial - how to cronjob

he Basic Format of a crontab/cronjob consists of 6 fields , placed on a single line and separated by spaces , formatted as follows





minute hour day month day-of-week command-line-to-execute


The acceptable values for each of the 6 fields are:
FieldRange of values
minute0-59
hour0-23
day1-31
month1-12
day-of-week0-7 (where both 0 and 7 mean Sun, 1 = Mon, 2 = Tue, etc)
command-line-to-executethe command to run along with the parameters to that command if any

The Fields have to be in that exact order ,with no empty or missing fields and everything must be placed on a single line

***********************************
Minute
***********************************
"Minute" is a number from 0 to 59. "Hour" is a number from 0 to 23. They represent the time of the day in a 24-hour day format, so for example, if you want a certain command to run at 5.30 am, you will have to code it as:

30 5
If you want something run at 8 pm, it has to be coded as

0 20

since 2000 hours is 8 pm in the 24-hour time format.
***********************************
Day and Month
***********************************
"Day" and "month" refer to dates. "Day" takes a value between 1 and 31, and "month", as you may have already guessed, can take any value between 1 and 12. So if you want a command run on 5th January at 9.15 am, your schedule should begin with the following:

15 9 5 1

***********************************
Day of week
***********************************

"Day-of-week" means basically which day you want your command to run. If you want your command to run on Sundays, use either 0 or 7 here. If you want it on Monday, use 1. (Note: if you are getting worried at this point how to combine all the various fields, some of which seem to contradict the other, don't worry. We're getting to that.)

The trick to scheduling things, say, once a day, or once in 2 hours or the like, is to use a wildcard character. A wildcard character is like the Joker in a pack of playing cards, that is, it is something that can represent any card in the pack. In a crontab file, the wildcard character "*" (the asterisk, without the quotes), represents every possible value for the field.
If you want a particular program to run, say, once every day at 10.45 am, the time portion of the cron schedule should read:

45 10 * * *
Here's how to read the above line.

The first two fields "45 10" means that you want it to run at 10.45. The next field, the day field, is set to * (the asterisk character) to show that we're talking about 10.45 every day, not just the 1st of the month (which would be "1") or the 30th of the month ("30") or some other number.
The month field is set to the asterisk as well. If we set some number in the month field, say "2", we will be saying that we only want the command to run at 10.45 in the month of February ("2"). Since that's not what we need, we put the asterisk to mean every month.
Similarly, the day-of-week field is set to the asterisk, because we want the command to run whether it's Sunday ("0") or Monday ("1") or whatever day.

More Examples: An Hourly Schedule

Now if you want a job to run every hour on the hour, you will have to set the time component of the crontab line as follows:
0 * * * *
Can you see why? The "0" means at the top of the hour, that is, when the minute readout on a digital clock shows "00". The asterisk in the hour field means every single hour. In other words, every hour, on the hour.

Alternate Hour or 3 Hourly Schedule

If you want something to run once every two hours, you will have to use the slash, "/", character in your field. The slash character is the "step" character. In the case of a two hourly schedule, your time component of your cron file will read:
0 */2 * * *
The second field, "*/2", means every alternate hour.
Similarly, if you want something to run every 3 hours, you can change that field to "*/3", and so on.

Other Examples

If you want a particular command to run only at 8.00am on the 1st and 20th of every month, you should code the time as:
0 8 1,20 * *
The comma, ",", means "and". If you are confused by the above line, remember that spaces are the field separators, not commas.
What does the following schedule mean?
2 3 4,5 6 7
Decoded, the above line says at 3:02 am on the 4th and 5th of June (6) and on every Sunday (7), run your program.
There are other possibilities in the time fields, and I won't go through all of them, since you already know enough to be able to construct whatever schedule you need.


How to specify the command line

The command-line-to-execute portion of the schedule is basically the command you want run at the specified time. For example, if you have a Perl script called "whatever.pl" that you want run every day at 11.30 am, your crontab schedule might read as follows:
30 11 * * * /your/directory/whatever.pl

Thanks to : http://www.thesitewizard.com/general/set-cron-job.shtml

Featured post

Vicidial With WebRTC

Vicidial With WebRTC VICIDial is well known open source call center software. It has been in use by many small to large scaled con...