Linux - NewbieThis 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
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.
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?
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 !
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.
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
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.