inicio del repositorio de scripts
This commit is contained in:
commit
be85567089
26
shutdown.sh
Normal file
26
shutdown.sh
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 0 21 * * * /home/web/scripts_linux/shutdown.sh >> /home/web/scripts_linux/cron.log 2>&1
|
||||||
|
# 0 23 * * * /home/web/scripts_linux/shutdown.sh >> /home/web/scripts_linux/cron.log 2>&1
|
||||||
|
|
||||||
|
# sudo chmod +x /ruta/al/scripts.sh
|
||||||
|
# sudo chmod -R 777 /ruta/carpeta/scripts_linux/
|
||||||
|
|
||||||
|
# Establecer PATH para evitar problemas con cron
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
# Obtener la fecha actual
|
||||||
|
d=$(date +"%d/%m/%Y %H:%M")
|
||||||
|
|
||||||
|
# Captura el nombre del usuario que ejecutó el script (en cron será root)
|
||||||
|
usr=${SUDO_USER:-$(whoami)}
|
||||||
|
|
||||||
|
# Definir la ruta del log (guardar siempre en /var/log para evitar problemas)
|
||||||
|
LOG_FILE="/var/log/shutdown_history.log"
|
||||||
|
|
||||||
|
# Registrar la ejecución en el log
|
||||||
|
echo "$d: Shutdown ejecutado por $usr" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Apagar el sistema
|
||||||
|
shutdown -h now
|
||||||
|
|
24
shutdown_weekends.sh
Normal file
24
shutdown_weekends.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# 0 9 * * * /home/web/scripts_linux/shutdown_weekends.sh >> /var/log/cron_shutdown_weekend.log 2>&1
|
||||||
|
|
||||||
|
# Establecer PATH para evitar problemas con cron
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
# Obtener la fecha actual y el día de la semana (0=Domingo, 6=Sábado)
|
||||||
|
d=$(date +"%d/%m/%Y %H:%M")
|
||||||
|
day_of_week=$(date +"%u") # 6 = Sábado, 7 = Domingo
|
||||||
|
|
||||||
|
# Captura el nombre del usuario que ejecutó el script (en cron será root)
|
||||||
|
usr=${SUDO_USER:-$(whoami)}
|
||||||
|
|
||||||
|
# Definir la ruta del log
|
||||||
|
LOG_FILE="/var/log/shutdown_weekend.log"
|
||||||
|
|
||||||
|
# Si es sábado (6) o domingo (7), apagar el equipo
|
||||||
|
if [[ "$day_of_week" -eq 6 || "$day_of_week" -eq 7 ]]; then
|
||||||
|
echo "$d: Shutdown ejecutado por $usr (Fin de semana)" >> "$LOG_FILE"
|
||||||
|
shutdown -h now
|
||||||
|
else
|
||||||
|
echo "$d: No es fin de semana, no se apaga el equipo." >> "$LOG_FILE"
|
||||||
|
fi
|
29
upgrade.sh
Normal file
29
upgrade.sh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 0 18 * * * /home/web/scripts_linux/upgrade.sh >> /home/web/scripts_linux/cron.log 2>&1
|
||||||
|
# sudo chmod +x /ruta/al/scripts.sh
|
||||||
|
# sudo chmod -R 777 /home/web/scripts_linux/
|
||||||
|
|
||||||
|
# Establecer PATH para asegurarse de que los comandos se encuentran
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||||
|
|
||||||
|
# Obtener la fecha actual
|
||||||
|
d=$(date +"%d/%m/%Y %H:%M")
|
||||||
|
|
||||||
|
# Captura el nombre del usuario que ejecutó el script
|
||||||
|
usr=$(who | awk '{print $1}' | head -n 1)
|
||||||
|
|
||||||
|
# Asegurar que el usuario no esté vacío, usar root como fallback
|
||||||
|
usr=${usr:-root}
|
||||||
|
|
||||||
|
# Definir la ruta del log
|
||||||
|
LOG_FILE="/home/$usr/scripts_linux/history_log.txt"
|
||||||
|
|
||||||
|
# Verificar si el directorio existe, si no, crearlo
|
||||||
|
mkdir -p "/home/$usr/scripts_linux"
|
||||||
|
|
||||||
|
# Registrar la ejecución en el log
|
||||||
|
echo "$d: upgrade" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Ejecutar actualización del sistema
|
||||||
|
apt-get update >> "$LOG_FILE" 2>&1
|
||||||
|
apt-get upgrade -y >> "$LOG_FILE" 2>&1
|
Loading…
x
Reference in New Issue
Block a user