Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Playing with bash...
PostPosted: Mon Jul 14, 2014 5:38 pm 
Offline
Senior Member

Joined: Wed May 13, 2009 1:32 pm
Posts: 737
Location: Italy
Hi,
this script
Code:
#!/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:
Code:
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?


Top
   
 Post subject: Re: Playing with bash...
PostPosted: Mon Jul 14, 2014 6:22 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
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")

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
 Post subject: Re: Playing with bash...
PostPosted: Tue Jul 15, 2014 4:08 am 
Offline
Senior Member

Joined: Wed May 13, 2009 1:32 pm
Posts: 737
Location: Italy
sweh wrote:
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
Code:
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group