写入文件时期望脚本文件名太长

Expect script file name too long when writing to a file

我是编码新手,这是我的第一个脚本。它一直工作到必须打开(创建)要写入的文件的程度。然后它无法给我一个错误 somepassedNickvariable.txt 文件名太长。我运行它作为用户"qbot"。

第一个期望的示例输出:

2016-08-05T23:32:42 73600,565 INF Chat: 'Quadro': !ustawdomek

第二个示例输出:

1. id=51890, Pepesza, pos=(473,1, 42,1, 1223,7), rot=(-66,1, 104,1, 0,0), remote=True, health=97, deaths=6, zombies=138, players=1, score=109, level=35, steamid=xxx, ip=xx.xx.xx.xx, ping=111
2. id=1141, Quadro, pos=(465,6, 87,1, -624,1), rot=(-30,9, 1620,0, 0,0), remote=True, health=187, deaths=1, zombies=525, players=0, score=520, level=84, steamid=xxx, ip=xx.xx.xx.xx, ping=24
Total of 6 in the game

任何帮助将不胜感激,因为我自己无法让它工作。

#!/usr/bin/expect
set timeout -1
spawn telnet localhost 8081
expect "Please enter password" {sleep 3; send "blahblah\r" }

while {1} {
expect \
{
  "*INF Chat: '*': !ustawdomek" {
            regexp {'(.+)':\s\!ustawdomek} $expect_out(buffer) match Nick;
            set listplayers "*Total of * in the game";
            send "lp\r"
            expect $listplayers {
regexp "$Nick\,\spos\=\(\(\(\[-\]\?\d+\)\,\d\,\s\(\[-\]\?\d+\)\,\d\,\s\(\[-\]\?\d+\)\,\d\)\)" $expect_out(buffer) match lok lok1 lok2 lok3
                    set file [open "/home/qbot/domki/$Nick.txt" w]
                    puts $file "$lok1 $lok2 $lok3"
                    close $file
                    send "pm $Nick \"\[QBOT\]Blahblah\"\r" }

             }
   timeout {break}
   eof {break}
}
}

我不完全理解这个脚本的语法。但我想这与 regexp {'(.+)':\s\!ustawdomek} $expect_out(buffer) match Nick; 有关 .+ 本身就是贪婪的正则表达式,应尽可能避免使用。我认为它试图匹配一个非常大的文件名。尝试使用更简单的正则表达式,它只允许单词匹配并可能限制文件名的大小。例如,\w{1,25} 或类似的东西。