How to monitor some processes
Hello,
Just looking for some advice. I am very new to Linux , so I am not that well experienced. I need to create a small list of processes in a monitor.conf file. A shell script needs to check the status of these processes and restart if they are down. This shell script needs to be run every couple of minutes. The output of the shell script needs to be recorded in a log file. So far I have created a blank monitor.conf file. I have gotten the shell script to automatically updated every couple of minutes The Shell script also sends some default test information to the log file. Can anyone guide me in how I go about doing this part ? A shell script needs to check the status of these processes and restart if they are down. I have put in the conf file the below commands but I am not sure if this is right. ps ax | grep httpd ps ax | grep apache I also dont know if the shell script should read from the conf file or if the conf file should send information to the shell script file. Thanks in advance Any advice would be greatly appreciated ! |
Hi -
You're definitely on the right track. A couple of suggestions: 1. "cron" would be a great way to periodically run your scripts 2. "ps ax|grep httpd" will work if your Apache daemon is named "httpd"; otherwise "ps ax|grep apache" will work if it's named "apache2". It could be either one, depending on your Linux distro and version. This syntax, however, will give you an EXTRA line: you'll also see an entry for the command itself. You can eliminate the extra line with the syntax "ps ax|grep httpd|grep -v grep". Another way to check the status, without using "ps", is: "/etc/init.d/httpd status" ... or, equivalently, "apache2ctl status" 3. If you need to (re)start it from your script, the syntax is: "/etc/init.d/httpd restart" 'Hope that helps .. PSM |
Thanks Paul,
At least I know I am on the right track I have added the below to my test.sh file Quote:
Quote:
I want my test.sh file to read the monitor.conf file one line at a time and print the information into the monitor.log file can you tell me if there is something wrong with my statement in the test.sh file ??? |
Scripts
Both of the files you posted do not work as you intended.
I am working on them and will post something that works for you. . . . |
Hi, alexandra12 -
1. Here's a quick'n'dirty example: Code:
monitor.lst: Code:
monitor.sh: Quote:
2. I'd also encourage you to look into "cron" (I gave a link in my earlier post). 3. Finally, please Google for "open source monitoring tools" (or a similar search). You might find a package that's already written, and ideal for your purposes. |
catching processes
It might be useful for us to know what you are doing and what the problem is.
However the posting by paulsm4 will not guarantee that the process is or isn't running. I have tested it and it returns processes that I just switched off as running. Also you might consider reading the bash book because the script you wrote lacks some basics i.e the sha bang and /bin/bash or sh or whatever. I think paulm4's advice is good. I am sure this is not a new desire for many users and it is bound to be solved. You just need to hunt the resource down. |
All times are GMT -5. The time now is 06:08 AM. |