[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

script to find files

Hi,

I use a java program to wite weblogic log files to db. I need to have a shell script to call the java prog with the names of the latest updataed log files except the most recent log files that is still being updated by the server. For example lets assume the log files are being writen in the server as below

Acces1.log
Acces2.log
Access3.log
Access4.log
Access.log

The script should pickup the acess*.log files, and pass theem to the java program as soon as they are written. However the current access.log should be ignored and no file should be passed twice.

Thanks in advance....
0
conversekid
Asked:
conversekid
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
oleggoldCommented:
You don't have too write script,it's 1 line operation
0
 
oleggoldCommented:
You can set up basic monitoring by doing something like ls -lrt acess*.log>java.prog
0
 
oleggoldCommented:
You can put this thing run in background by just adding &

 ls -lrt acess*.log>java.prog &

or , if You don't want anyu output
nohup ls -lrt acess*.log>java.prog & >/dev/null

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
conversekidAuthor Commented:
Hi, thanks for the comments.. Issue is that we cant have the same log file e inserted into db more than once . If I add this in a cron job or infinite loop all the logs will repeatedly go into the db. We need just one copy of each log file to go to the java program and in-turn to db..

Every line we have in each access log is to be inserted into db as a row. It works like a web-analytic solution where in using the db, we can calculate the statistics about the number of hits per ip/user etc., for  any given period of time

Thanks
0
 
hvillanuCommented:
Hi

You say's "as soon as they write"
Then can use
#tail -f access1.log
To "see" the log online
And can add the code to pass at java at the end...
#tail -f access1.log > java...

Or can create a script that list the logs, then put on one file and finaly pass it to java, something like:
################################################
#Script to create a unique log and pass to java.
echo listing logs...
cd /var/log/
ls Access?.log > /temp/list_Access.lst
cd /temp
for i in `cat list_Access.lst`
do
echo copying $i
 cp /var/log/$i /temp/
done
 echo catting...
for j in `cat list_Access.lst`
do
 echo Adding... $j
 cat /temp/$j >> /temp/Access-all.log
done
rm /temp/list_Access.lst
##<put code to pass Java Here>
cat Access-all.log > java...
#
# EOF
################################################

-hope helps-

0
 
conversekidAuthor Commented:
Hi, Thanks for the reply. This script will send all the access.log files to db. When we add the same to cron, we need it send only the recently written/updated files to db so that no two files will be written twice...

Thanks
0
 
joe_maniacCommented:
The script can not know which files you have already saved in db. I'd suggest to pass all (*) files to Java program, and in this program decide with which of them to proceed.

*) To get names of all logs but the last (recent) one, you can use e.g.: ls -rt1 access*.log | head -n-1
0
 
joe_maniacCommented:
...unless you use some temporary file to store names of passed logs as hvillanu suggested.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now