2016-09-22 202 views
0

我有腳本「proc備份」。我必須爲每個目錄許多單詞允許或不允許。 我認爲這是一個數組的integra。但我沒有領先...陣列允許不允許

還是有什麼更簡單的?

bind pubm - "*fertig*" backup 

proc backup {nick host handle channel text} { 
    set name[lindex [split [stripcodes bcru $text]] 2] 
    set dir[lindex [split [stripcodes bcru $text]] 4] 

    if {[catch {exec sh backup.sh $dir $name} error]} { 
     putlog $error 
    } 

    putnow "PRIVMSG $channel :backup $name done"; 
} 

array set allowed { 
    "dir1"   "to rar" 
    "dir2"   "backupserver1 " 
    "dir3"   "2016 2017" 
} 

array set not_allowed { 
    "dir1"   "test crap" 
    "dir2"   "old backupserver2 jpg zip" 
    "dir3"   "2015 2014 2013 2012 2011 2010 209 19" 
} 

編輯:從IRC

行:(LINDEX 2和4)

運行backup.sh只有當這個詞在名稱是

WORD0 WORD1 backupserver1 WORD3 DIR2

當另一個字是

word0 word1 bac kupserver55 WORD3 DIR2

無法運行backup.sh

WORD0字1測試WORD3 DIR1 WORD0字1廢話WORD3 DIR1

運行backup.sh只有當這個詞中的名字是

WORD0 WORD1黑WORD3 dir1

只有在$ name中允許的字中有一個字時才運行。 當$ name中的not_allowed中的單詞是不可運行時。

+0

請再寫一些關於你期望發生什麼,什麼不發生的事情。現在,我不明白'allowed'和'not_allowed'數組的真正含義。 –

+0

例如:當在dir1($ dir)中的文本包括($ name)「to」或「rar」(從允許的數組集合中)然後make if {[catch {exec sh backup.sh ...., dir1($ dir)文本包括($ name)「test」或「crap」(從數組集合not_allowed)然後停止(retourn 0),我希望它更好。問候 –

回答

0

以下2行缺少變量名和值之間的空格。

​​

試試這個:

set name [lindex [split [stripcodes bcru $text]] 2] 
set dir [lindex [split [stripcodes bcru $text]] 4] 
+0

是thx,它從副本刪除..但這不是問題:) –

0

我現在做這個測試,當我有一個字當時的工作PERFEKT,

"dir1"   "rar" 

有2個字

"dir1"   "rar to" 

不工作。

我想作出迴應。如果字是「RAR」或字「到」從$ relname文字

bind pubm - "*fertig*" trade 

proc backup {nick host handle channel text} { 

set name [lindex [split [stripcodes bcru $text]] 2] 
set dir [lindex [split [stripcodes bcru $text]] 4] 

set rulesall [rulesallow $dir $release] 

putnow "PRIVMSG $channel :rulesall $rulesall" 
} 


array set allowed { 
"dir1"   "rar" 

} 


proc rulesallow { cat relname} { 
global allowed 
foreach {category allowede} [array get allowed] { 
    if { [string match -nocase "*$allowede*" "$relname"] } { 
    return $allowede; 
    } else { 

    } 
} 
} 

測試已經sh命令刪除。

Regards