Python Scripts: fix log wrintig & only write 25 GiB data to disk
This commit is contained in:
parent
a1b3a0f9a6
commit
e51b96a901
1 changed files with 9 additions and 5 deletions
|
@ -9,14 +9,18 @@ from datetime import datetime
|
||||||
def run_cmd(cmd, log_file, check=True, capture_output=True):
|
def run_cmd(cmd, log_file, check=True, capture_output=True):
|
||||||
print(f"Running: {cmd}")
|
print(f"Running: {cmd}")
|
||||||
result = subprocess.run(cmd, shell=True, capture_output=capture_output, text=True)
|
result = subprocess.run(cmd, shell=True, capture_output=capture_output, text=True)
|
||||||
|
|
||||||
log_file.write(f"\n$ {cmd}\n")
|
log_file.write(f"\n$ {cmd}\n")
|
||||||
if result.stdout:
|
if result.stdout:
|
||||||
log_file.write(result.stdout)
|
log_file.write(result.stdout)
|
||||||
if result.stderr:
|
if result.stderr:
|
||||||
log_file.write(result.stderr)
|
log_file.write(result.stderr)
|
||||||
|
log_file.flush() # ✅ Flush after writing
|
||||||
|
|
||||||
if check and result.returncode != 0:
|
if check and result.returncode != 0:
|
||||||
print(f"Command failed: {cmd}\n{result.stderr}")
|
print(f"[!] Non-zero exit code ({result.returncode}) for: {cmd}")
|
||||||
sys.exit(1)
|
if result.stderr:
|
||||||
|
print(result.stderr.strip())
|
||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,13 +85,13 @@ def run_badblocks(device, log_file):
|
||||||
|
|
||||||
|
|
||||||
def fill_random(device, log_file):
|
def fill_random(device, log_file):
|
||||||
print("Overwriting disk with random data...")
|
print("Writing 25 GiB of random data to disk...")
|
||||||
run_cmd(
|
run_cmd(
|
||||||
f"sudo dd if=/dev/urandom of={device} bs=1M status=progress",
|
f"sudo dd if=/dev/urandom of={device} bs=1M count=25600 status=progress",
|
||||||
log_file,
|
log_file,
|
||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
print("Random data written to disk.")
|
print("Random data write complete.")
|
||||||
|
|
||||||
|
|
||||||
def run_fio(device, rw_mode, log_file, bs="4k", runtime=30):
|
def run_fio(device, rw_mode, log_file, bs="4k", runtime=30):
|
||||||
|
|
Loading…
Add table
Reference in a new issue