You have multiple syntax errors here.
d=date
assigns the string date
to the variable d
and then attempts to run the token "+%h %d"
as a command while this assignment is in place. You seem to be looking for d=$(date "+%h %d")
which runs date "+%h %d"
and assigns the output to the variable d
.
- You then use
grep d
but this will of course grep for the literal string d
, not the variable.
- Without quoting, the Awk script will have
$1
replaced with the first argument to the current shell script, $2
with the second, etc. You are likely to receive a syntax error from Awk unless all these variables happen to contain valid Awk code.
- You'll also want to avoid those useless
grep
s
You probably were trying to write something like
sudo cat /var/log/secure |
awk -v d="$(date "+%h %d")" '
/Invalid/ && ($0 ~ d) { print $1,$2,$8,$10}' |
sort | uniq -c
In some more detail, we assign the output of date
to the Awk variable d
and use the Awk pattern-matching language to only print
lines which match this variable and the static pattern Invalid
.