shell script to replicate the log files from one location to another in real time

Hi,

On the server, we have app log files in this location /app/logs/error.log
On the same server, in a real time, we would like to replicate that into /var/ directory.

if someone has already done this, please share the script.

Thanks in advance.

This can be done in a variety of ways.

One of the quick and easy way:

tail -f source_file > dest_file

This process must be continuosly running.

1 Like

how about make a link ?

ln -s /app/logs/error.log /var/error.log

hard/soft link depends on your requirement.

1 Like

Should the two logfiles be exact copies of each other or do you will to append any new log entries that are added to /app/logs/error.log to /var/error.log?

Will any other processbe writing to the /var/error.log file?
What should happen if the /app logfile is truncated?

Thanks all to provide the useful information.

Let me give some more background

There are two physical servers which are tie to a SAN disk. One server is active[A] and the other is standby[b].At any given time, only active server has mount to the san disk which means access to /app/logs/error.log

If active server has problem, then it will failover to standby server and that server become active and will have access to /app/logs/error.log

The idea is

1) if server A is active, and app is generating the logs in error.log, then copy that into server A /var/error.log. so lets say if there are three errors 1,2,3, then it should copy those three into var/error.log on server A

2) if server B is active, and app is generating the logs in error.log, then copy that into server B /var/errorl.log. so lets say if there are new errors 4,5,6, then it should copy those new errors into var/error.log on server B.

The error.log file never rollback / truncated. it just keep growing.

Not sure how to handle this situation. if the error.log file is too big and someone decided to archive and empty the file.

i think we need some well structured shell script