V
V
Vitaly2014-04-22 04:29:50
linux
Vitaly, 2014-04-22 04:29:50

How to monitor changes in the linux (solaris) folder?

Good day, I really hope for your help, a question for linux experts (more precisely solaris), is there any way (preferably using only standard functionality) to monitor changes in the folder, and redirect the changes to an external server (ala syslog)?
The situation is as follows:
there are many files (more than 500) with random names in the folder, changes occur to about 30 of them all the time. I would like to receive from the server what and in what files has changed (more precisely, it has been added, because the files are logs).
It is impossible to change the logging mechanism, the program is already written for us :)
It is also impossible to share a folder as an smb resource, there are only SCP or SSH.
Using "synchronization in SCP" is also not suitable, because it will download the entire file each time (and there are files much larger than 1 GB), it cannot "download" changes.
My idea, as it could be in linux, is a daemon that monitors changes in a folder and, when a file changes, reads the lines from point to change and sends it to some external server (in the worst case, writes to a file on a network resource), after which he remembers where he finished reading, and next time he reads from a new point.
For Windows, a similar "daemon" fits in 15 lines in C #, but there are servers with linux and I can’t imagine how to do this on them :( I hope for your advice, because I didn’t work much with linux.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
A
Alexey Cheremisin, 2014-04-22
@leahch

Actually, there is rsync for these purposes, which synchronizes and transfers files and directories. Only changes are synced, not all files. en.wikipedia.org/wiki/Rsync
Well, there is also an inotify mechanism for keeping track of files en.wikipedia.org/wiki/Inotify

E
Egor, 2014-04-22
@methodx

You can use inotify, FAM or Gamin. Also, supervisord
is suitable for solving the problem .

D
Dan Ivanov, 2014-04-22
@ptchol

Solaris 11+ has a file event notification. Perhaps there are analogues of the inotifywatch \ inotifywait utilities based on it.
However, if you are friendly with the code, then you can implement them yourself in a couple of hundred lines ( https://blogs.oracle.com/praks/entry/file_events_n...
Or, again, a very stupid but, in principle, working option, stat'om check for file changes in a loop :)

3
3vi1_0n3, 2014-07-23
@3vi1_0n3

Since linux is mentioned, this can be done in it with two very short scripts using netcat:
1) Sending:

#!/bin/bash
tail -f 1.log | nc 127.0.0.1 8080

Option to send without netcat:
#!/bin/bash
tail -f 1.log >/dev/tcp/127.0.0.1/8080

2) Receipt:
#!/bin/bash
nc -l 127.0.0.1 -p 8080 > 2.log

We run the first script so that it works in the background, like this:
The second script for working in the background is also the same.
In theory, there is a GNU tail for Solaris, like netcat too. But I would like to know the version of Solaris, if this is what you use, in order to look more natively. In Solaris it can be very different.

M
macik, 2021-12-01
@macik

incrontab and you will be happy.
I just can't do it all. I use this all the time.

/home/camin/    IN_MOVED_TO     /python/cam_file.py $#

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question