A
A
apaicer2021-11-16 20:48:43
linux
apaicer, 2021-11-16 20:48:43

How to switch writing to file via inode?

Good evening!

Please tell me a hypothetical situation.

Conventionally, there is a web server that writes the standard access.log log, and it so happened that this file filled up all the space on the server.

There are 2 ways, for example, delete this file and reboot the web server, or you can create the same file and transfer the entry to it via inode.

But I did not find exactly how to do this from a practical point of view or googled badly.

Prompt, please, commands, I will also be glad to the literature where I can learn about it.

Or is it enough that ln access.log new_access.lgo and rm access.log?
In fact, they will have the same inode, but it looks somehow ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
paran0id, 2021-11-16
@apaicer

You can null out the contents of the file.
You can send SIGUSR1 to the server, if it knows how to handle it, so that it reopens the files.
Once "sober" the file name (path) in the inode, the server writes in the inode. You can rename the file and then kick the SIGUSR1 server or restart.
For the future - configure logrotate.

S
Saboteur, 2021-11-17
@saboteur_kiev

If you just reset the file, then the usual
echo "" > file
if you need to save part of the file, then you can read a piece from the file and write it to it

tmp=$(tail -n 1000 file)
echo "$tmp" > file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question