Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of automatically adding crontab to script

Shulou Source: shulou.com Published: 2022-06-03 08:06:07 11月15日 Update

This article mainly explains the "script automatically add crontab writing method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "script automatically add crontab writing method" bar!

The code is as follows:

#! / bin/sh

BASEDIR= `dirname $0` /..

BASEDIR= `(cd "$BASEDIR"; pwd)`

PROGRAM=$BASEDIR/bin/daemon.sh

CRONTAB_CMD= "* / 1 * sh $PROGRAM once > / dev/null 2 > & 1 &"

(crontab-l 2 > / dev/null | grep-Fv $PROGRAM; echo "$CRONTAB_CMD") | crontab-

COUNT= `crontab-l | grep $PROGRAM | grep-v "grep" | wc-l `

If [$COUNT-lt 1]; then

Echo "fail to add crontab $PROGRAM"

Exit 1

Fi

Thank you for reading, the above is the "script automatically add crontab writing method" of the content, after the study of this article, I believe you automatically add the script to add crontab writing method of this problem has a deeper understanding, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Methods scripts learning content code that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Shulou Technology Shulou Information MySQL