Cron每1或2分钟就会运行一次

阿布·雷安

我已经注意到,我的cron脚本在执行后每1或2分钟就会运行近1个小时,因为我有很多cron作业,有时我无法访问我的网站,因此浏览器会搜索很长时间:

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

disk_space.sh将检查每个分区中的磁盘空间,如果磁盘空间大于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

谢谢四人的支持

有人支持莫妮卡

您的cron语法不正确。*表示every,因此它将在凌晨5点到6点之间每分钟运行一次。例如5:23匹配,因为5匹配5和23匹配*。

您希望分钟字段中为零,因此它仅在凌晨5点运行一次。

更正的行:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何每8小时1分钟运行一次CRON

让cron作业每30分钟运行一次-使用cron.hourly?

每小时以外的每30分钟之后,每隔30分钟就会显示一次Java Quartz Scheduler cron表达式

为什么我的cron配置的GitHub Action无法每2分钟运行一次?

如何使用systemd替换要每五分钟运行一次的cron作业?

Cron字符串每5分钟运行一次?

两小时之间每10分钟运行一次Cron作业

30分钟之前每5分钟执行一次Cron工作

Cronjob每30分钟运行一次

每5分钟运行一次.sh

如何每1小时10分钟执行一次cron作业

每2小时执行一次cron作业,持续30分钟

每2分钟调度一次android

在上午7点至晚上7点之间每15分钟运行一次Cron

设置为让脚本在每1分钟触发内仅每2分钟发出一次呼叫的模式。(Google App脚本)

每5分钟在拱门上执行一次cron作业

Cron突然每15分钟调用一次脚本

在两次之间每5分钟执行一次cron作业

配置在Hangfire中每15分钟执行一次的cron作业

我如何每30分钟执行一次cron作业?

每5分钟执行一次cron作业

您如何每5分钟执行一次cron作业?

每30分钟执行一次Cron语法| gitlab

如何每15分钟运行一次android函数,尤其是每天15分钟?

每15分钟运行一次crontab不能在linux redhat上运行

在运行主程序时每5分钟运行一次功能

如何停止正在运行的每10分钟运行一次的.bat文件

每1分钟运行一次springboot应用程序,并同步每个控制器

从00:x0之前的1秒开始每10分钟运行一次Azure函数