Skip to content

Instantly share code, notes, and snippets.

@Mez0
Last active December 5, 2024 13:41
Show Gist options
  • Save Mez0/68213e5297cc43d3ce602fafd319721a to your computer and use it in GitHub Desktop.
Save Mez0/68213e5297cc43d3ce602fafd319721a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Define the path to the config file
CONFIG_FILE="/opt/nezha/agent/config.yml"
# Check if the config file exists
if [[ -f "$CONFIG_FILE" ]]; then
# Use sed to change disable_command_execute from false to true
sed -i 's/disable_command_execute: false/disable_command_execute: true/' "$CONFIG_FILE"
# Check if the sed command was successful
if [[ $? -eq 0 ]]; then
echo "Configuration updated successfully."
# Restart the nezha-agent service
sudo systemctl restart nezha-agent.service
# Check if the service restarted successfully
if [[ $? -eq 0 ]]; then
echo "Service nezha-agent restarted successfully."
else
echo "Failed to restart nezha-agent service."
fi
else
echo "Failed to update the configuration file."
fi
else
echo "Configuration file not found: $CONFIG_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment