Files
gkachele-saas/backups/backup-20260114-085602/local/setup_cron.py
2026-01-17 11:40:17 +01:00

41 lines
1.1 KiB
Python

#!/usr/bin/env python3
# Script para configurar cron en Raspberry
import subprocess
import sys
# Obtener crontab actual
try:
result = subprocess.run(['sudo', 'crontab', '-u', 'pi', '-l'],
capture_output=True, text=True, check=False)
current_cron = result.stdout
except:
current_cron = ""
# Nueva entrada
new_entry = "*/5 * * * * /home/pi/scripts/update-raspberry-cron.sh\n"
# Verificar si ya existe
if new_entry.strip() in current_cron:
print("✅ La entrada de cron ya existe")
sys.exit(0)
# Agregar nueva entrada
new_cron = current_cron + new_entry
# Escribir nuevo crontab
try:
process = subprocess.Popen(['sudo', 'crontab', '-u', 'pi', '-'],
stdin=subprocess.PIPE, text=True)
process.communicate(input=new_cron)
if process.returncode == 0:
print("✅ Cron configurado exitosamente")
# Mostrar crontab
subprocess.run(['sudo', 'crontab', '-u', 'pi', '-l'])
else:
print("❌ Error configurando cron")
sys.exit(1)
except Exception as e:
print(f"❌ Error: {e}")
sys.exit(1)