Last active
June 5, 2018 15:07
-
-
Save turbo-ele/c3b422c0de8f4fbcbf4d31cc2653289a to your computer and use it in GitHub Desktop.
Renames log symlinks of kubernetes pods due to bug on update
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 characters
## 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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment