本文介绍了在接收与 xinetd 的传入连接时执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 xinetd 在某个端口接收到连接时执行一个 shell 脚本.为此,请遵循本教程:[在此处输入链接描述][1]

I want xinetd to execute a shell script when a connection is received on a certain port. To accomplish this, followed this tutorial: [enter link description here][1]

不幸的是,整件事并没有像我希望的那样奏效,这就是我要展示的原因你我的配置

Unfortunately, the whole thing doesn't work as I hoped that's why I am going to showyou my configuration.

xinetd 调用的脚本位于/usr/local/bin.它可以毫无问题地执行:

The script that is called by xinetd is located at /usr/local/bin. It can be executed without any problems:

#!/bin/bash
echo "connection received"

/etc/xinetd.d/testservice 有这个内容:

/etc/xinetd.d/testservice has this content:

service testservice
{
        disable         = no
        socket_type     = stream
        protocol        = tcp
        port              = 5900
        log_on_success += USERID
        log_on_failure += USERID
        server          = /usr/local/bin/testservice
        user            = root
        instances       = UNLIMITED
        wait            = no
        log_type        = SYSLOG daemon debug
}

在/etc/services 我添加了这一行:

In /etc/services I added this line:

testservice        5900/tcp

然后我用 service xinetd restart

最后,我尝试连接到客户端:

Finally, I tried to connect to the client:

nc host1 5900

谁能告诉我这里出了什么问题?

Could someone please tell me what went wrong here?

以下是/var/log/syslog.1 中的一些行:

Here are some lines from /var/log/syslog.1:

Nov 22 10:07:33 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/chargen [file=/etc/xinetd.conf] [line=17]
Nov 22 10:07:33 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/daytime [file=/etc/xinetd.d/daytime] [line=28]
Nov 22 10:07:33 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/discard [file=/etc/xinetd.d/discard] [line=26]
Nov 22 10:07:33 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/echo [file=/etc/xinetd.d/echo] [line=25]
Nov 22 10:07:33 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/exec [file=/etc/xinetd.d/exec] [line=26]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/login [file=/etc/xinetd.d/login] [line=8]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/rexec [file=/etc/xinetd.d/rexec] [line=13]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/rexecd [file=/etc/xinetd.d/rexecd] [line=0]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/rlogin [file=/etc/xinetd.d/rlogin] [line=10]
Nov 22 10:07:34 ubuntu1 acpid: 33 rules loaded
Nov 22 10:07:34 ubuntu1 acpid: waiting for events: event logging is off
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/rsh [file=/etc/xinetd.d/rsh] [line=10]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/shell [file=/etc/xinetd.d/shell] [line=11]
Nov 22 10:07:34 ubuntu1 xinetd[886]: Reading included configuration file: /etc/xinetd.d/time [file=/etc/xinetd.d/time] [line=11]
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing chargen
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing chargen
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing daytime
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing daytime
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing discard
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing discard
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing echo
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing echo
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing time
Nov 22 10:07:34 ubuntu1 xinetd[886]: removing time
Nov 22 10:07:34 ubuntu1 xinetd[886]: bind failed (Address already in use (errno = 98)). service = exec
Nov 22 10:07:34 ubuntu1 xinetd[886]: Service exec failed to start and is deactivated.
Nov 22 10:07:34 ubuntu1 xinetd[886]: bind failed (Address already in use (errno = 98)). service = login
Nov 22 10:07:34 ubuntu1 xinetd[886]: Service login failed to start and is deactivated.
Nov 22 10:07:34 ubuntu1 xinetd[886]: bind failed (Address already in use (errno = 98)). service = shell
Nov 22 10:07:34 ubuntu1 xinetd[886]: Service shell failed to start and is deactivated.
Nov 22 10:07:34 ubuntu1 xinetd[886]: xinetd Version 2.3.14 started with libwrap loadavg options compiled in.
Nov 22 10:07:34 ubuntu1 xinetd[886]: Started working: 3 available services

其他服务似乎在运行:

netstat -an |egrep '原型|听'

netstat -an | egrep 'Proto|LISTEN'

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:512             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:513             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:514             0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp6       0      0 ::1:631                 :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     10248    /run/user/user1/keyring-0bvpKQ/control
unix  2      [ ACC ]     STREAM     LISTENING     10250    /run/user/user1/keyring-0bvpKQ/ssh
unix  2      [ ACC ]     STREAM     LISTENING     8087     /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     10038    @/tmp/dbus-3MCEY0sgqz
unix  2      [ ACC ]     STREAM     LISTENING     689      @/com/ubuntu/upstart
unix  2      [ ACC ]     STREAM     LISTENING     7758     /var/run/cups/cups.sock
unix  2      [ ACC ]     STREAM     LISTENING     986      @/org/bluez/audio
unix  2      [ ACC ]     STREAM     LISTENING     10192    /tmp/.pcmanfm-socket--0-user1
unix  2      [ ACC ]     STREAM     LISTENING     8086     @/tmp/.X11-unix/X0
unix  2      [ ACC ]     SEQPACKET  LISTENING     882      /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     913      /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     10028    /tmp/ssh-1PFvKafVKThh/agent.1507
unix  2      [ ACC ]     STREAM     LISTENING     34594    /tmp/.lxterminal-socket:0-user1
unix  2      [ ACC ]     STREAM     LISTENING     968      /var/run/avahi-daemon/socket
unix  2      [ ACC ]     STREAM     LISTENING     982      /var/run/sdp
unix  2      [ ACC ]     STREAM     LISTENING     10629    /tmp/.menu-cached-:0-user1
unix  2      [ ACC ]     STREAM     LISTENING     8433     /var/run/acpid.socket

也许这也有帮助:

service xinetd restart
stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.73" (uid=1000 pid=5311 comm="stop xinetd ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.74" (uid=1000 pid=5308 comm="start xinetd ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")

推荐答案

service testservice
{
    port            = 5900
    socket_type     = stream
    protocol        = tcp
    wait            = no
    user            = root
    server          = /usr/bin/testscript.sh
    server_args     = test
}

你说得对,我无法让你的工作.上面好像.

You're right, I couldn't get yours to work. The above seemed to.

确保 testscript.sh 设置为 +x 并且在顶部包含 #!/bin/sh(在您的示例中它确实是这样显示的)

Make sure that testscript.sh is set +x and at the top contains #!/bin/sh (in your example it does appear that way)

这篇关于在接收与 xinetd 的传入连接时执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 10:30