Percebi que meu cron script continua rodando a cada 1 ou 2 minutos após a execução por quase 1 hora, já que tenho muitos cron jobs, às vezes não consigo acessar meu site, o navegador fica pesquisando por muito tempo:
# Check disk space each 5 AM everyday
* 5 * * * /root/Scripts/Misc/disk_space.sh
disk_space.sh verificará o espaço em disco em cada partição e me notificará por e-mail se o espaço em disco for superior a 95%
disk_space.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
Obrigado quatro pelo seu apoio
Responder1
Sua sintaxe cron está incorreta. * significatodo, portanto, entre 5h e 6h, ele será executado a cada minuto. Ex: 5:23 partidas, porque 5 partidas 5 e 23 partidas*.
Você deseja um zero no campo de minutos, para que ele seja executado apenas uma vez, exatamente às 5h.
Linha corrigida:
0 5 * * * /root/Scripts/Misc/disk_space.sh