-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdryrunconfigs.py
More file actions
43 lines (37 loc) · 1.92 KB
/
dryrunconfigs.py
File metadata and controls
43 lines (37 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import shutil
import subprocess
# Directory containing the generated configuration files
generated_configs_dir = "generated_configs"
# Path to the proftpd configuration file
proftpd_conf_path = "/home/marthijnvd/master/docs/proftpd.conf"
# Path to the dryrun script
dryrun_script = "./test.sh"
base_output_folder = "/home/marthijnvd/master/docs/outputs"
# Iterate over each configuration file in the directory
for config_file in os.listdir(generated_configs_dir):
if config_file.endswith(".conf"):
# Extract the number from the configuration file name
try:
config_number = int(''.join(filter(str.isdigit, config_file)))
except ValueError:
print(f"Skipping {config_file}: No valid number found in the name.")
continue
# Full path to the current configuration file
config_path = os.path.join(generated_configs_dir, config_file)
# Create a unique output folder for this configuration
output_folder = os.path.join(base_output_folder, f"output_{config_number}")
os.makedirs(output_folder, exist_ok=True)
# Replace the proftpd.conf file with the current configuration
shutil.copy(config_path, proftpd_conf_path)
print(f"Replaced {proftpd_conf_path} with {config_path}")
# Rename the configuration file to proftpd.conf
renamed_config_path = os.path.join(generated_configs_dir, f"proftpd_{config_number}.conf")
os.rename(config_path, renamed_config_path)
print(f"Renamed {config_file} to {renamed_config_path}")
# Execute the dryrun script with the extracted number as an argument
try:
subprocess.run([dryrun_script, str(config_number)], check=True)
print(f"Executed {dryrun_script} with argument {config_number}")
except subprocess.CalledProcessError as e:
print(f"Error executing {dryrun_script} with argument {config_number}: {e}")