尝试为我的服务器上正在运行的两个应用程序配置两个 CronJob。
我必须在 ConrJob 上放置的命令是:
wget -q -O- http://myDOMAIN/cron/index
我已经做了:
crontab -e
对文件的编辑:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/1 * * * * wget -q -O- http://myDOMAIN/cron/index
*/1 * * * * wget -q -O- http://myDOMAIN2/cron/index
但是我没有收到来自 APP 的成功邮件通知。在 Maildir 文件夹 /home/master/(自己的邮件服务器)中,我仅收到以下消息:
Return-Path: <master@myDOMAIN>
X-Original-To: master
Delivered-To: master@myDOMAIN
Received: by myDOMAIN (Postfix, from userid 1000)
id 0DA2F1A1F2B; Fri, 16 Jun 2017 16:42:01 +0200 (CEST)
From: root@myDOMAIN (Cron Daemon)
To: master@myDOMAIN
Subject: Cron <master@node01-ubuntu> /myDOMAIN/cron/index
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/master>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=master>
Message-Id: <20170616144201.0DA2F1A1F2B@mmyDOMAIN>
Date: Fri, 16 Jun 2017 16:42:01 +0200 (CEST)
/bin/sh: 1: /myDOMAIN/cron/index: not found
答案1
cronjobs 需要完整路径:尝试
/usr/bin/wget -q -O- http://myDOMAIN/cron/index
或
/usr/bin/wget -q -O-http://myDOMAIN/cron/index2> $logfile
并将 $logfile 添加到您的邮件中
答案2
您可以为此使用脚本(例如,类似这样的脚本cron.sh
):
在脚本中,添加所有想要运行的行为:
#!/bin/bash
wget -q -O- http://myDOMAIN/cron/index
wget -q -O- http://myDOMAIN2/cron/index
然后chmod a+x /path/to/croh.sh
最后,将以下内容添加到您的 crontab:
*/1 * * * * /path/to/croh.sh