Operating System - HP-UX
1831562 Members
4293 Online
110025 Solutions
New Discussion

Re: Help With parameter in Script

 
SOLVED
Go to solution
Steven Chen_1
Super Advisor

Help With parameter in Script

Hi,

I need some help from script export for parameter use. I have a script to get date and count of email number to send out to put into message. The codes:

------------
bbb=`date`
ccc=`date '+%b %e'`
ddd=`grep ipaddress syslog.log | grep -c "$ccc 02:"`

echo "Hello, " >>mesg
echo "We have sent $ddd email messages on $bbb." >> mesg
---------------------------
grep -c "$ccc 02:" is not working. Put in the first part of line is the same.

I try "sed -n /$ccc 02:/p' filename", not working. (Supposed I have a file created by
"grep ipaddress syslog > filename" first.

I don't know why the parameter can not work this way.

Please help.

Thanks a lot,

Steven
Steve
15 REPLIES 15
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Help With parameter in Script

Hi Steven,

I see nothing glaringly obvious. Can you attach
a small piece of your logfile. You may be having problems matching 's.

Clay
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Help With parameter in Script

Hi Steven:

I'm with Clay. I don't see anything obviously wrong. One thought, however: are you sure that you have IPaddresses and not DNS names in syslog?

...JRF...
MANOJ SRIVASTAVA
Honored Contributor

Re: Help With parameter in Script

Hi Steven

First just try

grep ipaddress syslog.log , it chould give you some output , incase there is no outpput then you can pipe that out . I dont thionk anythin else looks wrong.

Manoj Srivastava
Steven Chen_1
Super Advisor

Re: Help With parameter in Script

Thank you for all the help. I should have made it clearer -- it is just not getting the result of what I get, but the code itself runs.

E.g. on the code:
-----------------------
ccc=`date '+%b %e'`
ddd=`grep ipaddress syslog.log | grep -c "$ccc 02:"`
-----------------------
I should have 700 counts today, but I get 800 counts instead including 100 counts from yesterday. So the 2nd grep filter is not working, though it lets condition through. Put it in the first grep place resulting the same.

That's what I would like to see the parameter $ccc working.

Can you help please?

Steven
Steve
James R. Ferguson
Acclaimed Contributor

Re: Help With parameter in Script

Hi Steven:

Would you post your syslog and the *values* of the interpreted variables you are using?

...JRF...
Ken Martin_1
Occasional Advisor

Re: Help With parameter in Script

Just for the heck of it try the following changes

ccc=`/bin/date '+%b %e'`
ddd=`grep ipaddress syslog.log | grep -c "${ccc} 02:"`
A. Clay Stephenson
Acclaimed Contributor

Re: Help With parameter in Script

Hi Steven,

Again nothing obvious; posting your logfile
(or at least a portion of it exhibiting the problem) will really help.


Clay
If it ain't broke, I can fix that.
Steven Chen_1
Super Advisor

Re: Help With parameter in Script

I could only get 0 count if I try "${ccc} 02", same as any other ways.

I would post some log files for reference:
---------------------------------------------

Jun 8 02:17:24 6C:IRIS sendmail[13277]: CAA13277: from=, size=1023, class=0, pri=31023, nrcpts=1, msgid=<200106080617.CAA13277@mai
l.appp.com>, proto=ESMTP, relay=exchs [111.222.333.444]

Jun 8 02:17:24 6C:IRIS sendmail[13283]: CAA13283: from=, size=1038, class=0, pri=31038, nrcpts=1, msgid=<200106080617.CAA13283@mai
l.appp.com>, proto=ESMTP, relay=exchs [111.222.333.444]
------------------------------------------

There is some problem on website for me to offer points for each who are so helpful. Will do.
Steve
Patrick Wallek
Honored Contributor

Re: Help With parameter in Script

I am looking at my syslog and I notice that in the date with single digit days there are 2 spaces between the month and day so it looks like "Jun7time". Could the additional space be part of your problem?

I'm grasping at straws here.
Steven Chen_1
Super Advisor

Re: Help With parameter in Script

Patric,

I notice the space issue. If I use "grep -c "Jun 8" syslog", I have no problem. Is it a matter of parameterfailing to work?

If I use "ddd=grep date|grep -c ipaddress syslog", I get all 800 counts. It tells me that the date part is problematic.
Steve
James R. Ferguson
Acclaimed Contributor

Re: Help With parameter in Script

Hi:

I don't think the is the problem since Steven is quoting his variables. Consider this:

# X=`date`
# echo $X
# echo "$X"

This is normal, expected shell behavior.

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Help With parameter in Script

Hi again Steven,

I think this will fix you, we need to eat the spaces:

mo=`date '+%b' | tr -d " "`
da=`date '+%e' | tr -d " "`
ccc="${mo} ${da}"

Put that in your script. I am curious why you only care about 02 hours.

Have fun, Clay
If it ain't broke, I can fix that.
Steven Chen_1
Super Advisor

Re: Help With parameter in Script

The space should not be the issue, as shown as follows:

-------------------
IRIS 50# date '+%b %e'
Jun 8

IRIS 51# date
Fri Jun 8 16:12:43 EDT 2001
----------------------

Both "Jun 8" have proper space in this system.

Any more help?
Steve
Steven Chen_1
Super Advisor

Re: Help With parameter in Script

I test the code in Linux and find it basically working. I use:

grep ipaddress|grep -c "Jun 8" syslog

and I get the correct count.

While I do not have confidence in this unix shell I am working with, can someone think of other editor that might work?

I know this works:
sed -n '/Jun 8 02:/p' syslog|wc -l

but I feel parameter for "Jun 8" is hard to accept.

Someone knows more about sed please?
Steve
A. Clay Stephenson
Acclaimed Contributor

Re: Help With parameter in Script

Hi Steven,

Your problem is that you are going to have to build the sed string 'on the fly'. I'm very puzzled by this, since %e always prints 2 characters.

Anyway if you want to use sed, do this:

mo=`date '+%b' | tr -d " "`
da=`date '+%e' | tr -d " "`
ccc="/${mo}[ ]*${da}[ ]*02:/p"
knt = `cat syslog | sed -n -e "${ccc}" | wc -l`
echo "${knt} entries found"

The idea is we build the sed string. The '[ ]*'
matches any number of spaces.

Try that, Clay
If it ain't broke, I can fix that.