Hi All/Anilsir,
Below code is working fine when the firewall is active/running before executing the code.
but it is failing when firewall is dead/stopped before executing the code.
when firewall is already dead/stopped and if we execute below code it is showing the error
"Unable to execute /usr/bin/systemctl status firewalld"
Please let me know how can i handle it ?
def is_firewall_service_running (): error_found = 0 output = "" cmd_list = ['/usr/bin/systemctl', 'status', 'firewalld'] try: output = subprocess.check_output(cmd_list) # nosec except subprocess.CalledProcessError: error_found = 1 print(" processor error in run ") except OSError: error_found = 1 print(" OS error in run") if error_found or not output: print("Unable to execute: " + ' '.join(cmd_list)) print(" failed to check running ") return False for item in output.splitlines(): item = item.decode() if re.search('Active', item) and re.search(r'running', item): return True return False
Try the command on shell and see what difference are you getting.
RegardsPassion: http://sysplay.in (Playing with Systems)
--
You received this message because you are subscribed to the Google Groups "SysPlay's Inside Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inside_linux...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/CAFO2MTf5%2B_k3XrK4UyjZBFT8_S%2Bi5UL2NktwjdJ90bGEUQhRJw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/8a0796fc-3d6c-2989-a456-3f3ca8b422f2%40sarika-pugs.com.
I mean the systemctl command directly and see what you get.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/CAFO2MTe45Tz8Spr6r_m%3DTktjtVbKbhbL6VaO6Rbz5rtpK4cMDQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/e76aa35f-a9ad-42e2-4de6-8caf266e1b37%40sarika-pugs.com.
What is the return status in each case? Check using "echo $?" immediately after the command.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/CAFO2MTd8vNJrxmiyM1iKiUb%3DvQFL6U%3DTmz-HSXDhrRXAT_bE4Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/65435fbb-fc36-c826-ec82-bf482c79cf23%40sarika-pugs.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inside_linux/65435fbb-fc36-c826-ec82-bf482c79cf23%40sarika-pugs.com.