Cronジョブが実行されない

Cronジョブが実行されない

私は毎日NodeJSスクリプトを実行するようにcronジョブを設定しました。

crontab -l

# 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
55 23 * * * /usr/bin/node /getGames/.

しかし、私のスクリプトは決して実行されません。スクリプトはファイルにデータを書き込み、ファイルの最後の変更時間は更新されません。スクリプトを手動で実行すると機能します。

なぜ動作しないのかわかりません。

ベストアンサー1

cronジョブは、またはを介してat実行されるか、batchデスクトップの同じランタイム環境では実行されません。変更やその他の環境変数の設定は、ジョブにPATH自動的に伝播されませんcron。たとえば、no$DISPLAYなので、GUIプログラムには特別な処理(読み取りman xhost)が必要です。

cron環境変数は、すべてのジョブの読み取りファイルで設定できます。crontabman 5 crontab

echo "=== set ===";set;echo "=== env ===";env | sort;echo "=== alias ===";alias各環境の結果を確認してください。

その行はデフォルトで解釈されるため、構文はcommandそれよりも単純なので、環境を設定した後に必要なプログラムを呼び出すスクリプト(実行可能、インストール、開始)を呼び出すことをお勧めします。crontab/bin/sh/bin/bashcommandbash#!/bin/bash

おすすめ記事