Cron 不运行我编写的 Cron 作业

Cron 不运行我编写的 Cron 作业

我写了一个 Cron Job 但它没有运行。知道为什么它不运行吗?

这是我希望运行的 Cron 作业:

#
#
#                   (day of month)                (day of week)
#  min   hou    dom (day of month)    mon     dow (day of week)    command
   *     *      *                     *       *                    /usr/bin/touch /DATA/z_test_$(date '+%Y-%m-%d_T%H-%M').txt >/dev/null 2>&1

它应该每分钟运行一次。
我希望它创建一个空文件并将其保存在 /DATA/ 目录中。

这是我的文件系统的根目录:

Tue Apr 11 [srv_data@Ora1 /home/michal]$ ls -lah /
total 28K
dr-xr-xr-x.  18 root     root      236 Apr  3 10:52 .
dr-xr-xr-x.  18 root     root      236 Apr  3 10:52 ..
lrwxrwxrwx.   1 root     root        7 Oct  9  2021 bin -> usr/bin
dr-xr-xr-x.   5 root     root     4.0K Mar 27 11:22 boot
drwxrwx--x.   2 srv_data srv_data 4.0K Apr 11 14:51 DATA
drwxr-xr-x.  18 root     root     3.2K Apr  4 12:20 dev
drwxr-xr-x. 115 root     root     8.0K Apr  5 14:37 etc
drwxr-xr-x.   4 root     root       36 Apr  6 08:58 home
lrwxrwxrwx.   1 root     root        7 Oct  9  2021 lib -> usr/lib
lrwxrwxrwx.   1 root     root        9 Oct  9  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root     root        6 Oct  9  2021 media
drwxr-xr-x.   2 root     root        6 Oct  9  2021 mnt
drwxr-xr-x.   2 root     root        6 Oct  9  2021 opt
dr-xr-xr-x. 304 root     root        0 Apr  4 12:20 proc
dr-xr-x---.   3 root     root      163 Apr 11 12:04 root
drwxr-xr-x.  39 root     root     1.1K Apr  4 12:20 run
lrwxrwxrwx.   1 root     root        8 Oct  9  2021 sbin -> usr/sbin
drwxr-xr-x.   2 root     root        6 Oct  9  2021 srv
dr-xr-xr-x.  13 root     root        0 Apr  4 12:20 sys
drwxrwxrwt.   6 root     root     4.0K Apr 11 15:14 tmp
drwxr-xr-x.  13 root     root      158 Mar 20 13:08 usr
drwxr-xr-x.  22 root     root     4.0K Mar 28 08:54 var

我以用户身份运行此 Cron 作业'srv_data',该用户有权在 /DATA/ 目录中创建和保存文件。

我也尝试过使用此命令并从用户运行它'srv_data'并且它有效。它在我期望的位置创建文件。

Tue Apr 11 [srv_data@Ora1 /home/michal]$ ls -lah /DATA
total 20K
drwxrwx--x.  2 srv_data srv_data 4.0K Apr 11 15:31  .
dr-xr-xr-x. 18 root     root      236 Apr  3 10:52  ..
-rwxrwx--x.  1 srv_data srv_data 1.7K Apr  4 10:14  blade_runner_the_movie_1982
-rw-r--r--.  1 srv_data srv_data  960 Apr 11 15:00  file_with_dates
-rwxrwx--x.  1 srv_data srv_data 2.2K Apr  4 10:09  mud_the_movie_2012
-rw-r--r--.  1 root     root        0 Apr 11 12:43  reczny_plik_01
-rw-r--r--.  1 root     root        0 Apr 11 12:43  reczny_plik_02
-rw-r--r--.  1 root     root        0 Apr 11 12:43  reczny_plik_03
-rw-r--r--.  1 root     root        0 Apr 11 12:43  reczny_plik_04
-rw-r--r--.  1 root     root        0 Apr 11 12:45  reczny_plik_05
-rw-r--r--.  1 root     root        0 Apr 11 12:45  reczny_plik_06
-rw-r--r--.  1 root     root        0 Apr 11 12:45  reczny_plik_07
-rw-r--r--.  1 root     root        0 Apr 11 12:45  reczny_plik_08
-rw-r--r--.  1 root     root        0 Apr 11 12:45  reczny_plik_09
-rwxrwx--x.  1 srv_data srv_data   66 Apr  3 11:18  synch_test_00
-rw-rw-r--.  1 srv_data srv_data    0 Apr  7 15:06  test_2023-04-07_T1506
-rw-rw-r--.  1 srv_data srv_data    0 Apr  7 15:14  test_2023-04-07_T1514
-rw-rw-r--.  1 srv_data srv_data    0 Apr  7 15:17  test_2023-04-07_T1517
-rw-rw-r--.  1 srv_data srv_data    0 Apr  7 15:22  test_2023-04-07_T15-22.txt
-rw-rw-r--.  1 michal   michal      0 Apr 11 14:46  z_test_2023-04-11_T14-46.txt
-rw-rw-r--.  1 michal   michal      0 Apr 11 14:51  z_test_2023-04-11_T14-51.txt
-rw-rw-r--.  1 srv_data srv_data    0 Apr 11 15:31  z_test_2023-04-11_T15-31.txt

这是文件的内容/var/log/cron

Apr 11 14:54:01 Ora1 CROND[22557]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:54:01 Ora1 CROND[22559]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:54:01 Ora1 CROND[22543]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:54:01 Ora1 CROND[22543]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:54:02 Ora1 CROND[22542]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:54:02 Ora1 CROND[22542]: (srv_data) CMDOUT ()
Apr 11 14:54:02 Ora1 CROND[22542]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  409.33 bytes/sec)
Apr 11 14:54:02 Ora1 CROND[22542]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)
Apr 11 14:55:01 Ora1 CROND[22586]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:55:01 Ora1 CROND[22584]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:55:01 Ora1 CROND[22570]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:55:01 Ora1 CROND[22570]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:55:01 Ora1 CROND[22569]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:55:01 Ora1 CROND[22569]: (srv_data) CMDOUT ()
Apr 11 14:55:01 Ora1 CROND[22569]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  1,228.00 bytes/sec)
Apr 11 14:55:01 Ora1 CROND[22569]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)
Apr 11 14:56:01 Ora1 CROND[22611]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:56:01 Ora1 CROND[22612]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:56:01 Ora1 CROND[22597]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:56:01 Ora1 CROND[22597]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:56:02 Ora1 CROND[22596]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:56:02 Ora1 CROND[22596]: (srv_data) CMDOUT ()
Apr 11 14:56:02 Ora1 CROND[22596]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  409.33 bytes/sec)
Apr 11 14:56:02 Ora1 CROND[22596]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)
Apr 11 14:57:01 Ora1 CROND[22641]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:57:01 Ora1 CROND[22639]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:57:01 Ora1 CROND[22625]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:57:01 Ora1 CROND[22625]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:57:01 Ora1 CROND[22624]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:57:01 Ora1 CROND[22624]: (srv_data) CMDOUT ()
Apr 11 14:57:01 Ora1 CROND[22624]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  1,228.00 bytes/sec)
Apr 11 14:57:01 Ora1 CROND[22624]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)
Apr 11 14:58:01 Ora1 CROND[22670]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:58:01 Ora1 CROND[22669]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:58:01 Ora1 CROND[22655]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:58:01 Ora1 CROND[22655]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:58:02 Ora1 CROND[22654]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:58:02 Ora1 CROND[22654]: (srv_data) CMDOUT ()
Apr 11 14:58:02 Ora1 CROND[22654]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  409.33 bytes/sec)
Apr 11 14:58:02 Ora1 CROND[22654]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)
Apr 11 14:59:01 Ora1 CROND[22698]: (srv_data) CMD (/home/srv_data/sync.sh)
Apr 11 14:59:01 Ora1 CROND[22699]: (srv_data) CMD (/usr/bin/touch /DATA/z_test_$(date '+)
Apr 11 14:59:01 Ora1 CROND[22683]: (srv_data) CMDOUT (/bin/sh: -c: line 0: unexpected EOF while looking for matching `'')
Apr 11 14:59:01 Ora1 CROND[22683]: (srv_data) CMDOUT (/bin/sh: -c: line 1: syntax error: unexpected end of file)
Apr 11 14:59:01 Ora1 CROND[22682]: (srv_data) CMDOUT (sending incremental file list)
Apr 11 14:59:01 Ora1 CROND[22682]: (srv_data) CMDOUT ()
Apr 11 14:59:01 Ora1 CROND[22682]: (srv_data) CMDOUT (sent 602 bytes  received 12 bytes  1,228.00 bytes/sec)
Apr 11 14:59:01 Ora1 CROND[22682]: (srv_data) CMDOUT (total size is 4,970  speedup is 8.09)

但我无法读取这个 cron 文件日志。我一点都没懂。该文件的第 5 列中的CMDand是什么?CMDOUT

什么/bin/sh: -c:意思??

相关内容