08 Mar 14, 09:45AM
(This post was last modified: 10 Mar 14, 09:36AM by RandumKiwi.)
Blueberry is correct. It won't create more than one file, so you'll only get the date when the tee command is executed. I know from experience there's a way around this (and it's not the way you probably think it is - because that way, breaks the logging), but I'm not going to explain this method to you.
Why?
Using the actual Linux logging system, would work better, as it has better redundancy built in (i.e. less chance of missing something, etc). Additionally, 'tee' will only append to a file every now-and-then, not straight away
So, I'll be helpful and give you some instructions to do what you want, for an rsyslog based system!
Step 1: You'll notice that everything from AssaultCube is already being logged to /var/log/syslog - so, no need to set up logging, just re-configure it to direct correctly.
Step 2: Open /etc/rsyslog.conf and find this line to change:
Replace it with the following, which will stop AssaultCube from being logged to /var/log/syslog:
Step 3: I recommend that above where the "RULES" list is, that you use the following extra commands:
Step 4: Below the commands you just copy/pasted, type this to redirect the log to a file, on a per-server basis. Ensure you replace "SERVERTAG" with whatever your server tag is. Remember, you can change this tag using the -N command-line argument:
Step 4 OPTIONAL: Use the following to just redirect ALL AssaultCube log data to a file:
Step 5: Below these, add the following line to stop any further data being logged to syslog:
Step 6: After all these changes, save the file. Reboot rsyslog:
Congratulations. You're now logging AssaultCube to a separate file (or files if you did it on a per-server basis) and not clogging your syslog file! Now we talk about logrotate. You should use logrotate (instead of your own script) - but, if you've come this far and don't trust me, I'm not going to explain why you should - go google it.
The following syslog commands will make your files be archived by date in the folder they were found.
Step 7: In this example, I'm going to pretend the config file is named /etc/logassaultcube.conf (replace the filepath in all the examples below if you choose a different name).
Step 8: Copy/paste the below code into the file, then adjust it according to your needs. If you're not sure what any of these options do, then type 'man logrotate':
Step 9: Set up a script run your logrotate file. In this example, I'm going to pretend the script file is named /etc/logassaultcube.sh (replace the filepath in all the examples below if you choose a different name).
Step 10: Copy/paste the below into that script file:
Step 11: Make the script file executable:
Step 12: Set up the super-user's cron to run logrotate at 11:59pm daily:
Step 13: Copy/paste this line into the crontab:
... AND, you're done.
Why?
Using the actual Linux logging system, would work better, as it has better redundancy built in (i.e. less chance of missing something, etc). Additionally, 'tee' will only append to a file every now-and-then, not straight away
So, I'll be helpful and give you some instructions to do what you want, for an rsyslog based system!
Step 1: You'll notice that everything from AssaultCube is already being logged to /var/log/syslog - so, no need to set up logging, just re-configure it to direct correctly.
Step 2: Open /etc/rsyslog.conf and find this line to change:
[SELECT ALL] Code:
*.*;auth,authpriv.none -/var/log/syslog
Replace it with the following, which will stop AssaultCube from being logged to /var/log/syslog:
[SELECT ALL] Code:
*.*;auth,authpriv.none;local6.none; -/var/log/syslog
Step 3: I recommend that above where the "RULES" list is, that you use the following extra commands:
[SELECT ALL] Code:
$ActionResumeRetryCount -1 # Infinite retries on insert-failure.
$ActionQueueType LinkedList # Memory-based logging, this one uses less memory/more CPU.
$ActionQueueFileName /var/log/emergency_rsyslog # Enables disk-assist, just in case of failure.
$ActionQueueMaxFileSize 250M # Limit emergency file-size, just in case.
$ActionQueueSaveOnShutdown on # Save in-memory data if rsyslog shuts down.
Step 4: Below the commands you just copy/pasted, type this to redirect the log to a file, on a per-server basis. Ensure you replace "SERVERTAG" with whatever your server tag is. Remember, you can change this tag using the -N command-line argument:
[SELECT ALL] Code:
if $syslogtag contains 'SERVERTAG' then /path/to/your/logfile.log
Step 4 OPTIONAL: Use the following to just redirect ALL AssaultCube log data to a file:
[SELECT ALL] Code:
if $programname == 'AssaultCube' then /path/to/your/logfile.log
Step 5: Below these, add the following line to stop any further data being logged to syslog:
[SELECT ALL] Code:
&~
Step 6: After all these changes, save the file. Reboot rsyslog:
[SELECT ALL] Code:
service rsyslog restart
Congratulations. You're now logging AssaultCube to a separate file (or files if you did it on a per-server basis) and not clogging your syslog file! Now we talk about logrotate. You should use logrotate (instead of your own script) - but, if you've come this far and don't trust me, I'm not going to explain why you should - go google it.
The following syslog commands will make your files be archived by date in the folder they were found.
Step 7: In this example, I'm going to pretend the config file is named /etc/logassaultcube.conf (replace the filepath in all the examples below if you choose a different name).
[SELECT ALL] Code:
nano -w /etc/logassaultcube.conf
Step 8: Copy/paste the below code into the file, then adjust it according to your needs. If you're not sure what any of these options do, then type 'man logrotate':
[SELECT ALL] Code:
nocompress # Don't tarball any of the logs.
/path/to/your/logfile.log {
rotate 36500 # Keep archived logs for 100 years.
daily # Rotate daily (not weekly, etc).
missingok # Rotate even if file is missing.
ifempty # Rotate even if file is empty.
noolddir # Don't archive logs into a separate folder.
dateext # Archived logs get dated, as per below:
dateformat -%Y-%m-%d # NAME-2014-03-09.log
extension .log # NAME-2014-03-09.log
create 0644 root root # Permissions for archived files.
postrotate
invoke-rc.d rsyslog rotate > /dev/null
endscript
}
Step 9: Set up a script run your logrotate file. In this example, I'm going to pretend the script file is named /etc/logassaultcube.sh (replace the filepath in all the examples below if you choose a different name).
[SELECT ALL] Code:
nano -w /etc/logassaultcube.sh
Step 10: Copy/paste the below into that script file:
[SELECT ALL] Code:
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate -f /etc/logassaultcube.conf
Step 11: Make the script file executable:
[SELECT ALL] Code:
chmod +x /etc/logassaultcube.sh
Step 12: Set up the super-user's cron to run logrotate at 11:59pm daily:
[SELECT ALL] Code:
sudo crontab -e
Step 13: Copy/paste this line into the crontab:
[SELECT ALL] Code:
59 23 * * * /etc/logassaultcube.sh
... AND, you're done.