ocserv 无法为传入连接执行脚本

问题描述

connect-script = /app/connect.sh
disconnect-script = /app/disconnect.sh

我在docker容器的ocserv.conf中有上面的配置,但是ocserv在有连接的时候执行不了/app/connect.sh。我从下面的日志中找不到真正的原因,有人遇到过同样的问题吗?

ocserv[26]: main[test]:xxx.xxx.179.135:57352 user of group 'Route' authenticated (using cookie)
ocserv[29]: main[test]:xxx.xxx.179.135:57352 executing script up /app/connect.sh
ocserv[29]: main[test]:xxx.xxx.179.135:57352 main-user.c:379: Could not execute script /app/connect.sh
ocserv[26]: main[test]:xxx.xxx.179.135:57352 connect-script exit status: 1
ocserv[26]: main[test]:xxx.xxx.179.135:57352 Failed authentication attempt for user 'test'

/app/connect.sh 的内容

#!/bin/bash

echo "$(date) [info] User ${USERNAME} Connected - Server: ${IP_REAL_LOCAL} VPN IP: ${IP_REMOTE}  Remote IP: ${IP_REAL} Device:${DEVICE}"

解决方法

好吧,我自己发现 docker 容器没有 bash,一种解决方案是将 #!/bin/bash 替换为 #!/bin/sh