2013-06-11 220 views
1

我想在awk中运行sendmail命令,但是我得到了下面的错误。在AWK中运行命令

awk命令

awk '{ split($0,array,"@"); gsub("\."," ",array[1]); system("sendEmail -f [email protected] -t " $1 "-u \"Hello from command\" -m \"Dear\ " array[1] \"-s smtp.boo.com:587 -xu khikho -xp khikho"}' email_list.txt

错误:

syntax error near unexpected token('`

email_list.txt头:

[email protected]

[email protected]

[email protected]

预先感谢您。

+0

能获得您的'system(“sendmail ...”)'一直使用硬代码值,然后尝试添加简单变量,并将数组作为最后一项。祝你好运。 – shellter

+0

系统内部引号(..)不正确。 –

+0

2错误我看到:“-s”选项之前没有空格;没有'系统('的右括号 –

回答

3

这是一个稍微不同的方法,并不是很困难得到(也没有使用awk在所有的bash只是字符串解析能力)的所有报价的权利:

while read address 
do 
    user=${address%%@*} 
    sendEmail -f [email protected] -t ${address} -u "Hello from command" -m "Dear ${user}" \ 
     -s smtp.boo.com:587 -xu khikho -xp khikho 
done < email_list.txt