文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Simple server monitoring with xinetd

Simple server monitoring with xinetd

时间:2010-05-01  来源:badb0y

You can use the simple but powerful xinetd on your Linux server to monitor almost anything on the server. Since xinetd just holds open a port and waits for a connection, you can tell it to run a script and return the output directly to the network stream.

To start, you'll need a script which will return data to stdout. In this example, I'll use a very simple script like the following:

#!/bin/bash
echo `uptime | egrep -o 'up ([0-9]+) days' | awk '{print $2}'`

This script pulls the number of days that the server has been online. Make the script executable with a chmod +x.

Now, you'll need to choose a port on which to run the xinetd service. I normally find a service in /etc/services that I won't be using on the server. In this example, I'll use isdnlog, which runs on port 20011. Create a file called /etc/xinetd.d/myscript and include the following in the file:

service isdnlog
{
        disable = no
        socket_type     = stream
        protocol        = tcp
        wait            = no
        user            = root
        server          = /path/to/script.sh
        server_args     = test
}

Depending on your xinetd version, you may need to enable your new configuration and restart xinetd:

chkconfig myscript on
/etc/init.d/xinetd restart

You can test your new script using netcat:

$ uptime
18:10:30 up 141 days, 19:17,  1 user,  load average: 0.65, 1.47, 1.14
$ nc localhost 20011
141

If you need to pass arguments to your script, just adjust the server_args line in the xinetd configuration. Also, be sure that your script is set up to handle the arguments.

相关阅读 更多 +
排行榜 更多 +
崩溃大陆2鱼竿如何获取

崩溃大陆2鱼竿如何获取

冒险解谜 下载
狙击手行动

狙击手行动

冒险解谜 下载
狙击突围行动最新版

狙击突围行动最新版

冒险解谜 下载