Cron sigue ejecutándose cada 1 o 2 minutos.

Cron sigue ejecutándose cada 1 o 2 minutos.

He notado que mi script cron sigue ejecutándose cada 1 o 2 minutos después de la ejecución durante casi 1 hora, ya que tengo muchos trabajos cron, a veces no puedo acceder a mi sitio web, el navegador sigue buscando durante mucho tiempo:

# Check disk space each 5 AM everyday
* 5 * * * /root/Scripts/Misc/disk_space.sh

disk_space.sh comprobará el espacio en disco en cada partición y me notificará por correo electrónico si el espacio en disco es superior al 95%

espacio_disco.sh

#!/bin/bash

#output=$(df -h | awk '{ print $5 }')

# Define date and time
Now=$(date +"%d-%m-%Y %T")

# Define hostname
hostname=$(hostname)

# Set alert limit, 95% we remove % for comparison
alert=95

# $1 is the partition name
# $5 is the used percentage
# NR>2: Start reading from row 2, otherwise will start reading from Strings (Use%)
# result of df -h will start output from Filesystem      Size  Used Avail Use% Mounted on
# and we cannot compare strings to digits while using -eg

# Print the df -h, then loop and read the result 
# NR>2: start reading from horizontal line number 2
df -h | awk 'NR>2 { print $1 " " $5 }' | while read output;
do

#echo $output

# Get partition name
partition=$(echo $output | awk '{ print $1 }')
#echo 'Partition: ' $partition
# Used space with percentage
useSpPer=$(echo $output | awk '{ print $2}')
#echo 'Used space %: ' $useSpPer

#used space (remove percentage)
useSp=$(echo -n $useSpPer | head -c -1)
#echo 'Used space digit: ' $useSp

#useSpDg=$(sed '1d' $useSp)
#echo $useSpDg

# Recap
#echo $useSp ' has ' $partition

# -ge is greatter than or equal
#echo "DEBUG [$useSp] [$alert]"

if [ $useSp -ge $alert ]; then
#echo $partition 'is running out of space with '$useSpPer

echo $Now ' ' $partition ' ' $useSpPer >> /root/Scripts/Misc/disk_space.log

dfRes=$(df -h)

# Inform the admin
echo -e "The partition $partition belongs to the host: $hostname is running out of space with $useSpPer.\n\nThis is the full result: \n\n$dfRes \n\nThis message is a warning to take an action, sent on $Now \nThank you for using this script" 2>&1 | sed '1!b;s/^/To: MAILID\nSubject: '$hostname': Disk Space\n\n/' | /usr/sbin/sendmail -t
#else
#echo 'Down'

fi

done
#echo $output

Gracias cuatro por su apoyo.

Respuesta1

Su sintaxis cron es incorrecta. * mediocada, por lo que entre las 5 y las 6 a. m. se ejecutará cada minuto. Por ejemplo, 5:23 coincide, porque 5 coincide con 5 y 23 coincide *.

Desea un cero en el campo de minutos, por lo que se ejecuta solo una vez exactamente a las 5 a. m.

Línea corregida:

0 5 * * * /root/Scripts/Misc/disk_space.sh

información relacionada