SWATCH – 我做错了什么?

我想/需要/渴望的是login时,用户login到我的FTP服务器。

问题:我不能按照我应该能够做到的方式进行色板工作。

这些数据被logging到一个文件中 – 但是这些日志当然不是很长。 我不能永远保留日志,但是我可以从中提取数据,分析数据,在其他地方存储结果。

如果有更好的办法做到这一点比以下,我都耳朵。

Swatch版本3.2.3

Perl 5.12

FTP:VSFTP

OS(testing):OS X 10.6.8

OS(生产):Solaris

从男人我看到我可以传递内容到一个命令..所以我应该能够回声这些值的文件,对他们的统计做一个sed / cut / uniq的事情。

$ man swatch (snip) exec command Execute command. The command may contain variables which are substituted with fields from the matched line. A $N will be replaced by the Nth field in the line. A $0 or $* will be replaced by the entire line. 

色板文件.swatchrc

 watchfor /OK LOGIN/ echo=red pipe "echo "0: $0 1:$1 2:$2 3:$3 4:$4 5:$5" >> /Users/bdunbar/dev/ftplog/output.txt" 

启动

 $ swatch -c /Users/bdunbar/.swatchrc --script-dir /Users/bdunbar/dev/ftplog -t /Users/bdunbar/dev/ftplog/vsftpd.log & 

testing

 echo "Mon July 9 03:11:07 2012 [pid 14938] [aetech] OK LOGIN: Client "206.209.255.227"" >> vsftpd.log 

结果 – 这是对TTY的回应。 这在服务器上是不需要的,但它确实告诉我一切正常。

 ftplog *** swatch version 3.2.3 (pid:25780) started at Mon Jul 9 15:23:33 CDT 2012 Mon July 9 03:11:07 2012 [pid 14938] [aetech] OK LOGIN: Client 206.209.255.227 

结果 – 不好! 我似乎不把variables发送到文本。

 $ tail -f output.txt 0: /Users/bdunbar/dev/ftplog/.swatch_script.25780 1: 2: 3: 4: 5: 

答案是: 手册页是错误的。

“整个行”的variables是$ _

因此,这将回应整个线路terminal。

 #.swatchrc watchfor /OK LOGIN/ exec echo $_ 

也可以把它发送到电子邮件,或在我的情况下,以进一步分析的文件。

我知道这可能会晚,但我有同样的问题,并find原因。 您必须在正则expression式中使用捕获组(这是数字引用的内容)。

例:

 /OK LOGIN: Client (.*)/ 

在您的示例中, $1将代表客户端IP地址。

您正在引用手册页的exec部分,但实际上使用的是pipe命令。

 pipe command[,keep_open] Pipe matched lines into command. Use the keep_open option to force the pipe to stay open until a different pipe action is run or until swatch exits. 

所以更改pipeexec并通过我的理解它应该工作。