damn, works like a charm i love it!
from approx 16000 logs to 350 folders in the logs dir, searching for
current date will get much easier :D
ty
and btw, this was windows.
------
//Rikard 'Zapy' Bremark
ComHem AB - http://www.comhem.se
Warzone.nu - http://www.warzone.nu
Warzone Short Valley
[email protected]
[email protected]
On 2011-03-06 16:16, Andre Müller wrote:
Update:
-Fixed a big bug. I've forgotten to use os.chdir, so the script
doens't do anything, when it was not inside the log dir.
+Now the script don't move the Logfiles of the current date.
+created an executable file for windows
CODE:
#!/usr/bin/python
from glob import iglob
from shutil import move
from datetime import datetime
from os import chdir, path, mkdir, stat
import sys
def usage():
print "Please run the Programm with %s /path/to/srcds_logfiles" %
sys.argv[0]
sys.exit()
if len(sys.argv)<= 1:
usage()
now = datetime.today().strftime('%Y-%m-%d')
if path.isdir(sys.argv[1]):
chdir(sys.argv[1])
for log in iglob('L???????.log'):
log_date=datetime.fromtimestamp(stat(log)[8])
dirname=datetime.strftime(log_date,'%Y-%m-%d')
if dirname == now:
continue
if not path.isdir(dirname) and not path.isfile(dirname):
mkdir(dirname)
if not path.isfile(path.join(dirname,log)):
move(log,dirname)
else:
usage()
Windows-Executable: http://rapidshare.com/files/451219516/log_sorter.zip
MD5:
7a3364ac975ca9cb66c1ee11b4521d76 log_sorter.exe
c94ee175212d0f745a91f8c0a9f0be67 log_sorter.zip
Please report bugs, when something doesn't work
Thx
Greetings
DeaD_EyE
sourceserver.info
2011/2/14 Andre Müller<[email protected]>:
Hi, I've written a little tool, wich looks for the timestamp of files
L???????.log and moves the files into the directories (YYYY-mm-dd).
Mybe it can help you. I think the python code works also under windows.
Usage: ./log_sorter.py /path/to/logs
Code:
#!/usr/bin/python
from glob import glob
from shutil import move
from datetime import datetime
from os import path, mkdir, stat
import sys
def usage():
print "Please run the Programm with %s /path/to/srcds_logfiles" %
sys.argv[0]
sys.exit()
if len(sys.argv)<= 1:
usage()
if path.isdir(sys.argv[1]):
for log in glob('L???????.log'):
log_date=datetime.fromtimestamp(stat(log)[8])
dirname=datetime.strftime(log_date,'%Y-%m-%d')
if not path.isdir(dirname) and not path.isfile(dirname):
mkdir(dirname)
move(log,dirname)
else:
usage()
I hope there is no error inside. I've tested it with some Logfiles
from my server.
Greetings
DeaD_EyE
sourceserver.info
2011/2/14 Harry Strongburg<[email protected]>:
On Sun, Feb 13, 2011 at 10:15:09PM +0100, Rikard Bremark wrote:
Hi!
Anyone here that has any log-scripts for their hlds/srcds setups
that moves yesterdays logs to a folder with yesterdays date?
Windows/Unix
I personally think grep is nice for sorthing them on-request. If you
want it to run once a day, crontab would probably work fine.
crontab -e:
0 0 * * * cd /path/to/logs/&& mkdir "`date +%F`"&& mv *.log "`date +%F`"
Make sure crond is running. That will run daily at midnight system time
and move all logs that were in that folder on that day into the folder
it made (i.e. if you ran that command right now, you would probably get
a folder called "2011-02-14").
I am unsure if srcds properly handles when a log file gets moved or
renamed, so you might want to be aware of that. Don't have time to check
right now.
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlds_linux
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlds_linux
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlds_linux