Crontab - Run in directory

后端 未结 2 1843
陌清茗
陌清茗 2020-12-07 09:58

I would like to set a job to run daily in the root crontab. But I would like it to execute it from a particular directory so it can find all the files it needs, since the ap

2条回答
  •  醉梦人生
    2020-12-07 10:36

    All jobs are executed by a shell, so start that shell snippet by a command to change the directory.

    cd /path/to/directory && ./bin/myapp
    

    Concerning the use of && instead of ;: normally it doesn't make a difference, but if the cd command fails (e.g. because the directory doesn't exist) with && the application isn't executed, whereas with ; it's executed (but not in the intended directory).

提交回复
热议问题