Playing with bash...
this script
#!/bin/bash
OGGI=$(date '+%b %e')
MAILLOG="/var/log/maillog"
SENT="status=sent"
GREPOGGI=$(grep $OGGI $MAILLOG | grep $SENT | grep -c $SENT)
echo $GREPOGGI
is supposed to count the sent email in the maillog file.
it does it very well but when I execute it says:
grep: 14: No such file or directory
27
where 27 is the number of the sent emails.
Why it works but than it says no such file?
2 Replies
You need "" around $OGGI in the grep because OGGI has a space in it.
GREPOGGI=$(grep "$OGGI" …)
However, grep | grep | grep is… umm.
Can't you just do
GREPOGGI=$(grep -c "^$OGGI .* $SENT")
@sweh:
Scripting 101
You need "" around $OGGI in the grep because OGGI has a space in it.
GREPOGGI=$(grep "$OGGI" …)
However, grep | grep | grep is… umm.
Can't you just do
GREPOGGI=$(grep -c "^$OGGI .* $SENT")
thank you sweh.
I noticed that grepping on
SENT="smtp.*to=.*sent.*"
gives me a more "reliable" number.
I don't care about the email sent from dovecot, dovecot carry emails around my system internally, I don't want to count that.
I want to count only the email sent to the external and that grep helped me.