我寫了一個awk腳本,從file.txt的和這個文件的每一行進行調用system("...")
需要一定的值。 問題是,終端只接受最後一次系統調用。系統(「」)調用
我需要每調用一次system("...")
呼叫,我的file.txt
的每一行都會被執行。
例如:file.txt
00:00:6c:19:8f:b1:d8:27 10.0.0.10 1
00:00:6c:19:8f:b1:d8:27 10.0.0.11 1
00:00:6c:19:8f:b1:d8:28 10.0.0.12 3
00:00:6c:19:8f:b1:d8:28 10.0.0.11 2
例如file.awk:
BEGIN {
}
{
switch_mac=$1
ip_dst=$2
output_port=$3
system("curl" " -d" " '{" "\"switch\""":" "\""switch_mac"\"""," "\"cookie\""":""\"1\"""," "\"priority\""":""\"2\"""," "\"eth_type\""":""\"0x0800\"""," "\"ipv4_dst\""":""\""ip_dst"\"""," "\"active\""":""\"true\"""," "\"actions\""":""\"output="output_port"\"""}'" " http://10.0.0.11:8080/wm/staticflowpusher/json")
//here i need to have the execution of the system call
}
你爲什麼要把它放在'awk'中? – pfnuesel
你想運行的實際'curl'命令是什麼 - 你能舉一個沒有awk所需的可怕引號的例子嗎? –
在AWK中,將兩個字符串相鄰放置是字符串連接。所以這些報價都不需要;他們什麼都不做,只是混淆了代碼。 – e0k