Can you write me a bash script which checks the time of day, checks a wireguard.conf to…
- User
Can you write me a bash script which checks the time of day, checks a wireguard.conf to be sure it is the appropriate one at that time, sets the correct wireguard config if necessary and reboots, and continues checking the time of day to verify the appropriate wireguard config is in use?
Assistant
Certainly! Here is a bash script that should accomplish the tasks you described:
#!/bin/bash # Function to check the time of day and set the appropriate wireguard config function set_wireguard_config() { # Check the current time of day current_time=$(date +%H) # Check if the current time is between 6am and 10pm if [[ $current_time -ge 6 && $current_time -le 22 ]]; then # Set the appropriate wireguard config wg_config="wireguard_config_day.conf" else # Set the appropriate wireguard config wg_config="wireguard_config_night.conf" fi # Set the wireguard config wg setconf $wg_config # Restart the wireguard service systemctl restart wg-quick@wg0 } # Set the appropriate wireguard config at startup set_wireguard_config # Continuously check the time of day and set the appropriate wireguard config as needed while true; do # Check the current time of day current_time=$(date +%H) # Check if the current time is between 6am and 10pm if [[ $current_time -ge 6 && $current_time -le 22 ]]; then # Set the appropriate wireguard config wg_config="wireguard_config_day.conf" else # Set the appropriate wireguard config wg_config="wireguard_config_night.conf" fi # Check if the current wireguard config is the same as the desired config current_wg_config=$(wg getconf | grep -oP '(?<=wireguard_config=).*') if [[ $current_wg_config != $wg_config ]]; then # Set the appropriate wireguard config wg setconf $wg_config # Restart the wireguard service systemctl restart wg-quick@wg0 fi # Sleep for 1 hour sleep 3600
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.