echo "`date '+%F %H:%M:%S'` User $common_name $trusted_ip logged in" >>/var/log/openvpn/$day
else
touch /var/log/openvpn/$day
echo "`date '+%F %H:%M:%S'` User $common_name $trusted_ip logged in" >>/var/log/openvpn/$day
fi
复制代码
disconnect.sh
#!/bin/bash
day=`date +%F`
if [ -f /var/log/openvpn/$day ];then
echo "`date '+%F %H:%M:%S'` User $common_name $trusted_ip logged off | Bytes received: $bytes_received | Bytes sent: $bytes_sent" >>/var/log/openvpn/$day
else
touch /var/log/openvpn/$day
echo "`date '+%F %H:%M:%S'` User $common_name $trusted_ip logged off | Bytes received: $bytes_received | Bytes sent: $bytes_sent" >>/var/log/openvpn/$day
fi
复制代码
给/var/log/openvpn目录加上666的权限
每次vpn连接和断开后都会在/var/log/openvpn目录下以当前日期为名的文件(如2010-05-25)里留下记录(断开后的记录可能稍有最多几分钟的延迟)
记录的内容如:
2010-05-25 12:12:12 User XX 123.123.123.123 logged off | Bytes received: 12345 | Bytes sent: 54321
2010-05-25 12:12:12 User XX 123.123.123.123 logged in