LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-10-2011, 03:10 AM   #1
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Rep: Reputation: 0
shell script


Hi.. I need a shell script, which will send mails only then when there is some problem with hard disk health, processor, when disk usage is exceeding 90% etc. Can anybody provide the basic idea regarding this?
 
Old 08-10-2011, 03:55 AM   #2
kiran_cyberpro
LQ Newbie
 
Registered: May 2007
Distribution: Fedora
Posts: 11

Rep: Reputation: 3
Lightbulb

Actually you can write a small PERL/PHP script.
You can call this script on demand (in any event, failure, or some issue), and trigger via shell or via command interface.

You can google php email script and or perl email scripts.
it is very easy. You can even create simple text based emails or advance html based emails also emails with attachments and so on. This should look like professional corporate emails.

Hope this suggestion helps you.

If you are too much new to shell scripts, then I suggest you to better learn php or PERL. They are more better languages than shell scripts. I agree shell scripts are very powerful, but the language constructs are too much looks old outdated format. So adapt to php/perl scripts, and call them via simple shell scripts !
 
1 members found this post helpful.
Old 08-10-2011, 06:57 AM   #3
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Rep: Reputation: 6
I myself would prefer rather Perl than Php, but it's really matter of choice.

I currently don't know any name of script which have this functionality, so if there won't be any other suggestions, I recommend you writing it yourself. (It's by the way, a great practice to get into Linux/Unix).

To make script of this functionality, you're going to need:

1) A way to send email. Either you can run mail server on your own computer, or use some program (possibly function of language too) to contact your (favourite) mail server.

2) A way to start this script regularly. Linux has pretty good apps in this section, take a look at some "cron" apps, my favourite is Vixie cron, and you probably have some already installed in your system.

3) A way to collect this kind of information. Information you are interested in "are not simply floating around in the system", and you are going to need specific applications and drivers to access it. Let me send you a quick list of apps I prefer:

-smartmontools: Used to access SMART data of disks which support it. The specific command (file) you use to start this application vary from distribution to distribution, but here on Gentoo it's "smartctl".

-df: File system disk storage usage.

-lm_sensors: Collect data from sensors, like cpu or motherboard temperature, fan speeds, etc.

-free: Memory/swap usage, to see if you are running out of RAM memory.

You can also "pickup" "critical" level entries from system logs. Logs are usually located in /var/log/ directory.

4) All the programs specified have their own way of output, you can process it with sed or similar applications.

5) Root access.

Feel free to correct/update me.

Skyer

Last edited by Skyer; 08-10-2011 at 07:18 AM.
 
1 members found this post helpful.
Old 08-15-2011, 03:22 AM   #4
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Original Poster
Rep: Reputation: 0
shell script

Could you please provide me some basic idea or any url links that how can I write script for smartmontools, loadaverage, disk usage etc. So I can get mails in the event of critical isssue i.e when disk usage exceed more than 90%, HDD health is not good, if there are any problem in apache, samba etc.


Quote:
Originally Posted by Skyer View Post
I myself would prefer rather Perl than Php, but it's really matter of choice.
ro
I currently don't know any name of script which have this functionality, so if there won't be any other suggestions, I recommend you writing it yourself. (It's by the way, a great practice to get into Linux/Unix).

To make script of this functionality, you're going to need:

1) A way to send email. Either you can run mail server on your own computer, or use some program (possibly function of language too) to contact your (favourite) mail server.

2) A way to start this script regularly. Linux has pretty good apps in this section, take a look at some "cron" apps, my favourite is Vixie cron, and you probably have some already installed in your system.

3) A way to collect this kind of information. Information you are interested in "are not simply floating around in the system", and you are going to need specific applications and drivers to access it. Let me send you a quick list of apps I prefer:

-smartmontools: Used to access SMART data of disks which support it. The specific command (file) you use to start this application vary from distribution to distribution, but here on Gentoo it's "smartctl".

-df: File system disk storage usage.

-lm_sensors: Collect data from sensors, like cpu or motherboard temperature, fan speeds, etc.

-free: Memory/swap usage, to see if you are running out of RAM memory.

You can also "pickup" "critical" level entries from system logs. Logs are usually located in /var/log/ directory.

4) All the programs specified have their own way of output, you can process it with sed or similar applications.

5) Root access.

Feel free to correct/update me.

Skyer
 
Old 08-15-2011, 08:44 AM   #5
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Rep: Reputation: 6
Well,
I myself would make this application as a shell script. It's good as interface with other programs, and provides all tools we need.

You probably use Bash. You can get enough information on Bash on tlpd - http://tldp.org/LDP/Bash-Beginners-Guide/html/

So, basically:
1. Initialize/check for all stuff we need. (Internet connection, root access, etc..)
2. Start running apps which provide information we need.
3. Redirect their output to (for example) sed, process it to get only infrmation you need (numbers probably) to check.
4. Run it through set of conditions.
5. If needed, send mail. I haven't done this myself in shell script yet, but in case there won't be any program for this, you can simply use member function of some programming language, or netcat.

Refer to manuals, if you need more information om respective applications.

Code:
man sed
man smartctl
...
I'm on vacation&mobile this week, so sorry typos and response times.



Skyer
 
1 members found this post helpful.
Old 08-15-2011, 10:38 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Could this be re-inventing a wheel that already exists?
 
Old 08-18-2011, 03:47 AM   #7
salemeni
Member
 
Registered: Aug 2011
Posts: 64

Rep: Reputation: Disabled
You can use nagios to supervise your PC.

generics array

Last edited by salemeni; 12-06-2011 at 03:00 AM.
 
1 members found this post helpful.
Old 08-18-2011, 10:50 AM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,617

Rep: Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963Reputation: 7963
Quote:
Originally Posted by ananthkadalur View Post
Could you please provide me some basic idea or any url links that how can I write script for smartmontools, loadaverage, disk usage etc. So I can get mails in the event of critical isssue i.e when disk usage exceed more than 90%, HDD health is not good, if there are any problem in apache, samba etc.
You've already been provided basic ideas. The tools for monitoring all the things you mentioned were listed by Skyer. Read the man pages for them. Once you can run them from the command line and get what you want, write your shell script to parse the output, and take action, just as you would for writing ANY shell script.

There are THOUSANDS of scripting tutorials you can easily find via Google, along with MANY sample scripts, if you try to look.
 
1 members found this post helpful.
Old 08-18-2011, 11:38 PM   #9
ananthkadalur
Member
 
Registered: Mar 2011
Posts: 38

Original Poster
Rep: Reputation: 0
shell script

I have heard about naios, munin etc. So Thank you very much for your kind reply and I'll follow the documentation for nagios.

Quote:
Originally Posted by salemeni View Post
You can use nagios to supervise your PC.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
Shell script calling shell script - List of all nikunjbadjatya Programming 7 04-13-2011 06:27 PM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 01:45 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:22 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