crontab
奇妙なことは、シェル端末ではうまく動作しますが、スクリプトは実行されません。スクリプトが改行で区切られていることを確認しました。しかし、台本の内容については疑問があります。後で実行するジョブをcrontab
実行します。run.sh
main.sh
これは/etc/crontab
:
* * */3 * * root source /opt/db_maintain/run.sh
run.sh
内部で呼び出される内容は次のとおりです。main.sh
#!/usr/bin/env bash
#********* Saman *********
TM=$(date --date='40 days ago' '+%F %T')
TARGET=/opt/db_maintain/main.sh
TIMESTAMP=$(echo ${TM} | tr --delete ': -')
export TIMESTAMP
source $TARGET "$TM"
これは次の始まりですmain.sh
。
#!/bin/bash
##!/usr/bin/env bash
#
# main program entry point
#
source /opt/db_maintain/functions.sh
source /opt/db_maintain/constants.sh
source /opt/db_maintain/settings.sh
source /root/PASSWD_PGRS.sh
#read -s -t 0 -n 9999
#read -s -p "Enter password for ${USERNAME}: " PASSWORD
ベストアンサー1
cronjobで次の構文を使用します。
* * */3 * * root /bin/bash /opt/db_maintain/run.sh
あなたはそれを使用しましたsource
。シェル組み込みコマンドからbash
。したがって、これはbash
シェル内またはシェルを介してのみ実行できますbash
。 crontabはシェルコマンドではなくバイナリファイルのみを実行します。したがって、可能であれば、絶対パスを使用してバイナリ(/bin/bash
)を呼び出す必要があります。