Skip to content

Instantly share code, notes, and snippets.

@turbo-ele
Last active June 5, 2018 15:07
Show Gist options
  • Select an option

  • Save turbo-ele/c3b422c0de8f4fbcbf4d31cc2653289a to your computer and use it in GitHub Desktop.

Select an option

Save turbo-ele/c3b422c0de8f4fbcbf4d31cc2653289a to your computer and use it in GitHub Desktop.

Revisions

  1. turbo-ele revised this gist Jun 5, 2018. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions rename_log_symlinks.py
    Original 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
  2. turbo-ele created this gist Jun 5, 2018.
    20 changes: 20 additions & 0 deletions rename_log_symlinks.py
    Original 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)