ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have an program running, (edited.x86 = game server) and the output is logged into a server.log with 2> in the command line.
I want to backup the server.log every day This isn't a problem but, i want to make the server.log empty without restarting the server. I tried several codes
Code:
cat server.log > backup.log
echo -n > server.log
these commands do make a backup.log with the output and it does empty the server.log BUT the log doesn't save any new outputs. it just stops, but the size of the file increases constantly.
Depending on the particulars of the server you're using and the method it's using for logging you may be able to kill -HUP the process to get it reopen its file handles. Although if it wasn't originally designed for unix/linux it's likely that will disconnect players.
Depending on how the process handles particular signals a HUP may kill and restart it or it may just close and reopen file handles or any variety of other things. Either research it for the individual application or try it while connected and see what happens and if new file handles get opened correctly a after log rotation.
So if im right, your saying that i have to kill the proces, wich means that the server will go offline and restart the server?
try this:
mv server.log server.log.1
tail -f server.log.1
the server should still be writing to server.log.1
killall -HUP edited.x86
now look and see if a new server.log got created. If it did, you're golden. You just mv/kill -HUP any time you want to rotate your log.
If it didn't you'll have to try something else.
Most long lived processes interpret sighup as a request to close and reopen the logfile handle, and reread the configuration, if there is one. The idea is that you can have the process perform some housekeeping, without, say, killing connections that are open to it.
nope. Kill doesn't kill processes, it sends signals to processes. Some signals normally cause a process to die. In fact, the _default_ signal that kill sends (if you don't give it one) is SIGTERM (15), which almost always stops the process.
You can send other useful signals to processes using kill also. Signals like USR1 and USR2 are reserved so that you can add a custom signal handler to respond to them. Occasionally people will use USR1 as the log rotation signal, and you'd say 'kill -USR1 12345'.
HUP or "hangup" is leftover from the days of serial comms, and wound up getting co-opted for log rotation (among other things)
Not particularly, it's just a poorly written daemon. You'll have to stop and restart it after you rotate the logs. Perhaps schedule it for Sunday at 4am or something similar.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.