Last active
June 5, 2018 15:07
-
-
Save turbo-ele/c3b422c0de8f4fbcbf4d31cc2653289a to your computer and use it in GitHub Desktop.
Revisions
-
turbo-ele revised this gist
Jun 5, 2018 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,10 @@ ## shell script: # HOST=$1 # scp -r ~/kubernetes/rename_log_symlinks.py $HOST:/home/admin/ # ssh $HOST "sudo python rename_log_symlinks.py" # ssh $HOST "rm rename_log_symlinks.py" import os import re import shutil -
turbo-ele created this gist
Jun 5, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import os import re import shutil basepath = '/var/log/pods' for parentdir in os.listdir(basepath): for content in os.listdir(os.path.join(basepath, parentdir)): search = re.search('(.*)_([0-9]{1}.log)', content) if not search: continue # Create new file path: /var/log/pods/asdf234/pod-name/0.log oldfilepath = os.path.join(basepath, parentdir, content) filepath = os.path.join( basepath, parentdir, search.group(1), search.group(2)) directory = os.path.dirname(filepath) print(oldfilepath) print(filepath) if not os.path.exists(directory): os.makedirs(directory) shutil.copyfile(oldfilepath, filepath)