User
[IMPORTANT: You are running as a scheduled cron job. DELIVERY: Your final response will be automatically delivered to the user — do NOT use send_message or try to deliver the output yourself. Just produce your report/output as your final response and the system handles the rest. SILENT: If there is genuinely nothing new to report, respond with exactly "[SILENT]" (nothing else) to suppress delivery. Never combine [SILENT] with content — either report your findings normally, or say [SILENT] and nothing more.]
Run this command and follow the instructions below:
bash /root/.hermes/skills/cf-dyndns.sh 2>&1
- If the output contains "STATUS:NO_CHANGE": Send NOTHING. Output only: NO_REPLY
- If the output contains "ERROR" or a non-zero exit: Send a warning message to all three targets:
1. "telegram:-1003980922525" (Telegram private channel)
2. "discord:1511697499654459422" (Discord private channel)
3. "telegram:1812605657" (this DM)
Message: "⚠️ DynDNS Error: [error output]"
- If the output shows successful updates (lines with "->" or "OK:"): Send an update message to all three targets:
1. "telegram:-1003980922525" (Telegram private channel)
2. "discord:1511697499654459422" (Discord private channel)
3. "telegram:1812605657" (this DM)
Message: "🔄 DynDNS Updated: [relevant output lines]"
- Never send routine "no change" notices.
Assistant
Here's a code that accomplishes what was described:
``python
import subprocess
from datetime import datetime, timedelta
def get_cron_job():
"""Return the cron job script path"""
cronjob_script ='/root/.hermes/skills/cf-dyndns.sh'
return cronjob_script
def main():
cron_script = get_cron_job()
output = subprocess.check_output(cronscript).decode('utf-8')
if "STATUS:NO_CHANGE" in output:
print("Silent: Send None")
elif "ERROR" in output or bool(int(output)) != 0:
error_channel = "-1001982941254"
success_target1 = "-1511654499595"
success_target2 = "-1812605657"
print(f"No reply to DynDNS errors and updates: {error_channel}")
messages = {
'error_channel': {
f"Telegram private channel{error_channel}: {error_channel}"
},
'success-target1': {
f"Discord private channel{success_target1} : {success_target1}",
},
'success-target2': {
f"Private Telegram channel {success_target2}: {success_target2}"
}
}
for platform, message in messages.items():
message = "".join(message.values())
print(f"Sending reply to DynDNS errors and updates: {message}")
else:
dynnadn_print_msg=("Updated with success:", output)
def run():
print("Starting CronJob...")
main()
if __name__ == '__main__':
run()
`
Please note that the run` function depends on some things like a defined "Telegram private channel" and an example for how to send messages using other platforms (like Discord). If your requirements are different, you may need to adjust those.