diff --git a/zpooliostat.py b/zpooliostat.py index 8d93143..619ccf9 100644 --- a/zpooliostat.py +++ b/zpooliostat.py @@ -36,14 +36,6 @@ def runZpoolIostat(): # Check the return code (0 for success) if result.returncode == 0: - # Check if the file exists - if not os.path.exists(filename): - # Create the file in write mode ('w') if it doesn't exist - with open(filename, "w", newline="") as csvfile: - csv_writer = csv.writer(csvfile) - # Write the header row (optional) - csv_writer.writerow(headerRow) - # Access the captured output as a string output = result.stdout @@ -81,6 +73,14 @@ def runZpoolIostat(): poolname = lineData[0] filename = poolname + "-zio.csv" + # Check if the file exists + if not os.path.exists(filename): + # Create the file in write mode ('w') if it doesn't exist + with open(filename, "w", newline="") as csvfile: + csv_writer = csv.writer(csvfile) + # Write the header row (optional) + csv_writer.writerow(headerRow) + # Now open the file in append mode ('a') with open(filename, "a", newline="") as csvfile: csv_writer = csv.writer(csvfile)