我正在尝试构建一个脚本,该脚本需要几天时间才能将日志回顾/分析作为参数:
script.sh 5
这将显示一个帐户过去5天的详细流量。它基于以下命令:
zcat $path/* |awk -vDate=`date -d'now-5 days' +[%d/%b/%Y:%H:%M:%S` ' { if ($4 > Date) print $1, $12, $15, $16, $17, $23, $24}' | sort | uniq -c | sort -fr | head
如何将该天数存储为变量并将其传递给awk?
days=$1
zcat $path/* |awk -vDate=`date -d'now-$days days' +[%d/%b/%Y:%H:%M:%S` ' { if ($4 > Date) print $1, $12, $15, $16, $17, $23, $24}' | sort | uniq -c | sort -fr | head
答案 0 :(得分:1)
您没有将变量传递给awk
,而是将其传递给date
awk -v date="$(date -d "now-$days days" +"[%d/%b/%Y:%H:%M:%S")" 'script'