Tracking centos server with bash script

In this article I will show you how to use bash shell to test the system periodically, to check the connection port 80, server load, queue exim, and mysql process … The script will automatically notify you via email if there are anything unusual.

Script will use a while loop to run every 2 minutes and check whether the case is running on the server. To run periodically, you can use command : crontab or screen


In this tutorial I will use screen on CentOS 6 (x64):

1. Install screen

Tools screen will help you to run multiple sessions on a terminal session and keep it alive unless you cancel or restart the server.
This utility is most effective when you want to install a program, and take the time that you are connecting to a remote ssh.

- To install screen you just use yum command:
# yum install screen -y

- To create a new session you use the command :screen -S Name_sesion_or_jobs
# screen -S monitor

- To exit the current screen, and work continues:
Press Ctr + A + D

- To list the session created by the screen:
# screen -ls

You should see

2. Run script on screen

- You create a file ( with the code below : (don’t forget to set your email address below “### Send mail alert and attachments log file” line near the end of the file.

- Set execute permissions(only run via root):
# chmod 0700

- Create a new session with the moniter name:
# screen -S moniter
- At the command prompt, run the script with password: namhuy
# ./
You should see

- You can view logs at: log2.txt in your email if your server load is greater than 10


    • namhuy says

      nice, thanks for sharing. Does sysdig “eat” alot of resource? I will try it on my testing box later ^^

Leave a Reply