猿问

Cron脚本已执行,但没有输出

我浏览了许多不同的主题,但没有找到解决问题的答案。我在Ubuntu服务器上创建了2个bash脚本,并试图定期执行它们。看来它们正在运行,但它们什么也没产生。它们是可执行的:


drwxr-xr-x 14 root root     4096 Mar 14 18:02 ..

-rwxr-xr-x  1 root root     2623 Apr 16 21:18 backup.pl

-rw-r--r--  1 root root 87066352 May 10 21:37 full_site_backup-10-4-2018.tar.gz

-rwxr-xr-x  1 root root      530 May 11 20:21 checkHealth.sh

drwxr-xr-x  2 root root     4096 May 11 20:35 .

所以这是我的脚本之一:


#!/bin/bash


# log stdout and stderr to two different files

exec >>/var/log/test.log 2>>/var/log/test.err.log


# ...and log every command we try to execute to stderr (aka looog.err.log)

# set -x


CODE=$(curl -s -o /dev/null -I -A "myuseragent" -w "%{http_code}" https://www.xxxxxxxxxxxxx.xxx/xxxx)


DATE=$(date)


if [ $CODE -gt 300 ]

then

    service mysql restart

    service tomcat8 restart

    >&2 echo "$DATE - KO !!!!!! code retour $CODE"

else

    echo "$DATE - OK, code $CODE"

fi

这是我的sudo crontab -e:


# m h  dom mon dow   command


0 2 * * * root /usr/bin/perl /var/backup/backup.pl

* * * * * root /bin/sh /var/backup/checkHealth.sh

这是我的sudo tail -f /var/log/cron.log:


May 11 20:39:01 ns381471 CRON[10778]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)

May 11 20:39:26 ns381471 crontab[10823]: (root) BEGIN EDIT (root)

May 11 20:40:01 ns381471 CRON[10880]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)

May 11 20:40:01 ns381471 CRON[10879]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)

May 11 20:40:30 ns381471 crontab[10823]: (root) END EDIT (root)

May 11 20:41:01 ns381471 CRON[10974]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)

May 11 20:41:01 ns381471 CRON[10975]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)

May 11 20:42:01 ns381471 CRON[11070]: (root) CMD (/usr/local/rtm/bin/rtm 2 > /dev/null 2> /dev/null)

May 11 20:42:01 ns381471 CRON[11071]: (root) CMD (root /bin/sh /var/backup/checkHealth.sh)

任何帮助,将不胜感激。谢谢


MM们
浏览 528回答 1
1回答
随时随地看视频慕课网APP
我要回答