unix script date help

January 10, 2011 at 11:17:20
Specs: Unix
Hello. I need a bat file to check a file for a keyword and return the count as a number.

Example:

I have a file called /logs/Load20101230.log on a Unix platform. Within this log file, I need to know how many times the word 'error' is contained in the file. But I am running into an issue. Every day this file is archived and a new file created with the current date. So I need the batch file to only check the current days log file, and not the previous days log file. Another issue I have is this. There is also a failover server that we use from time to time. I need to check this server for a log file of the current date. If there is no log file of the current date, I need the script to retrun a 0.

Any help would be appreciated.


See More: unix script date help

Report •


#1
January 10, 2011 at 13:52:09
u want to run the script on unix or in windows?

Subhash Chandra.


Report •

#2
January 10, 2011 at 16:47:02
This needs to run on Unix.

Report •

#3
January 10, 2011 at 17:52:12
This only checks the local file.


#!/bin/sh

file=`date "+/logs/Load%Y%m%d.log"`

if [ -f $file ]
then
grep -c error $file
exit 0
else
echo $file does not exist
exit 1
fi


Report •

Related Solutions


Ask Question