Last active
February 16, 2016 08:39
-
-
Save ksingh7/e8f273e5988ec68eb8ac to your computer and use it in GitHub Desktop.
CentOS7_clear_journal_error
This file contains 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
#!/bin/python | |
import subprocess | |
cmd = "journalctl --verify" | |
restart_journal_service = "False" | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) | |
out, err = p.communicate() | |
p_status = p.wait() | |
if p_status >= 1: | |
error_string=err.split() | |
for i in range(len(error_string)-1,0,-1): | |
temp = error_string[i] | |
if temp.find("Bad") > -1 or temp.find("Cannot") > -1: | |
remove_journal_log = "rm -rf "+error_string[i-1] | |
p = subprocess.Popen(remove_journal_log, stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) | |
restart_journal_service = "True" | |
if restart_journal_service == "True": | |
p = subprocess.Popen(['systemctl','restart',' systemd-journald.service'], stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) | |
p_status = p.wait() | |
out, err = p.communicate() | |
if p_status == 0: | |
print "Journal logs cleaned" | |
else: | |
print "There was some error while cleaning journal logs" | |
print err | |
print "Journal script completed successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote this patch to fix CentOS7 Journal problem