在crontab中使用方括号和-x

时间:2022-07-26 21:43:21

I'm trying to add a new entry into crontab, the issue I have is that all other entries are written like so:

我想在crontab中添加一个新条目,我的问题是所有其他条目都是这样写的:

0 0 * * * [ -x /home/test/test_reports/nightly ] && /home/test/test_reports/nightly

What is the purpose of [ -x /home/test/test_reports/nightly ]?

[-x /home/ test_reports/ nightly_reports]的目的是什么?

I tried to Google it but with no luck..

我想把它拆开来,但运气不好。

1 个解决方案

#1


3  

The options within [ ] can be found in man test:

[]中的选项可以在man test中找到:

-x FILE

- x文件

FILE exists and execute (or search) permission is granted

文件存在并执行(或搜索)权限被授予

So what these lines are doing is to check if the file is executable (and of course if it exists) and, if true, execute it.

因此,这些行要做的就是检查文件是否可执行(当然,如果存在的话),如果是真的,就执行它。

#1


3  

The options within [ ] can be found in man test:

[]中的选项可以在man test中找到:

-x FILE

- x文件

FILE exists and execute (or search) permission is granted

文件存在并执行(或搜索)权限被授予

So what these lines are doing is to check if the file is executable (and of course if it exists) and, if true, execute it.

因此,这些行要做的就是检查文件是否可执行(当然,如果存在的话),如果是真的,就执行它。