LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-896511/)

ananthkadalur 08-10-2011 03:10 AM

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?

kiran_cyberpro 08-10-2011 03:55 AM

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 !

Skyer 08-10-2011 06:57 AM

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

ananthkadalur 08-15-2011 03:22 AM

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 (Post 4438634)
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


Skyer 08-15-2011 08:44 AM

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

catkin 08-15-2011 10:38 AM

Could this be re-inventing a wheel that already exists?

salemeni 08-18-2011 03:47 AM

You can use nagios to supervise your PC.

generics array

TB0ne 08-18-2011 10:50 AM

Quote:

Originally Posted by ananthkadalur (Post 4443265)
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.

ananthkadalur 08-18-2011 11:38 PM

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 (Post 4446426)
You can use nagios to supervise your PC.



All times are GMT -5. The time now is 03:19 AM.