rsync从shell获得成功,但抱怨;语法或用法错误“;来自crontab
以下crontab行(在CentOS 7.6上) 此外,当我从shell运行该crontab行时,它可以工作:rsync从shell获得成功,但抱怨;语法或用法错误“;来自crontab,cron,centos7,rsync,Cron,Centos7,Rsync,以下crontab行(在CentOS 7.6上) 此外,当我从shell运行该crontab行时,它可以工作: qa@docker /tmp$ rsync -rav --remove-source-files --files-from=<(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} \;) /home/qa/buildbot/master/packages/rhel7 1
qa@docker /tmp$ rsync -rav --remove-source-files --files-from=<(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} \;) /home/qa/buildbot/master/packages/rhel7 192.168.1.31:/local/raid0/buildbotpackages/packages/rhel7
sending incremental file list
sent 18 bytes received 12 bytes 20.00 bytes/sec
total size is 0 speedup is 0.00
qa@docker /tmp$
qa@docker/tmp$rsync-rav--删除源文件--文件from=中断的cron作业通常是在cron使用的不同shell中测试命令而导致的。大多数流行的交互式shell,如bash
和zsh
以及标准的/bin/sh
(由cron使用)都有类似的基本语法,因为它们都是Bourne shell的后代。它们之间的相似性很强,您可以暂时认为cron的命令语法与登录shell相同
当您将更复杂的命令放入crontab时,您会发现它们之间存在差异。在您的示例中,我怀疑命令替换操作符cron使用/bin/sh
运行命令,这将不支持交互式shell的所有高级语法。使用替换命令您可以将rsync
命令放在shell脚本中(从指定bash--#!/bin/bash
或#!/usr/bin/env bash
的shebang行开始),然后从cron
运行脚本。感谢您的回答,@Wumpus。如果你把它写在一个答案里,我可以为你的声誉做出贡献。只是插嘴而已。尝试用完整路径替换rsync。通常是(/usr/bin/rsync)。
From: (Cron Daemon) <crontab@docker.local>
Subject: Cron <qa@docker> rsync -rav --remove-source-files --files-from=<(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} \;) /home/qa/buildbot/master/packages/rhel7 192.168.1.31:/local/raid0/buildbotpackages/packages/rhel7
rsync: failed to open files-from file <(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} ;): No such file or directory
rsync error: syntax or usage error (code 1) at main.c(1567) [client=3.1.2]
1557 SIGACTMASK(SIGINT, sig_int);
1558 SIGACTMASK(SIGHUP, sig_int);
1559 SIGACTMASK(SIGTERM, sig_int);
1560 #if defined HAVE_SIGACTION && HAVE_SIGPROCMASK
1561 sigprocmask(SIG_UNBLOCK, &sigmask, NULL);
1562 #endif
1563
1564 /* Ignore SIGPIPE; we consistently check error codes and will
1565 * see the EPIPE. */
1566 SIGACTION(SIGPIPE, SIG_IGN);
1567 #ifdef SIGXFSZ
1568 SIGACTION(SIGXFSZ, SIG_IGN);
1569 #endif
1570
1571 /* Initialize change_dir() here because on some old systems getcwd
1572 * (implemented by forking "pwd" and reading its output) doesn't
1573 * work when there are other child processes. Also, on all systems
1574 * that implement getcwd that way "pwd" can't be found after chroot. */
1575 change_dir(NULL, CD_NORMAL);
1576
1577 init_flist();
qa@docker /tmp$ rsync -rav --remove-source-files --files-from=<(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} \;) /home/qa/buildbot/master/packages/rhel7 192.168.1.31:/local/raid0/buildbotpackages/packages/rhel7
sending incremental file list
sent 18 bytes received 12 bytes 20.00 bytes/sec
total size is 0 speedup is 0.00
qa@docker /tmp$
BIG-FANCY-PROMPT%>$ sh
$ rsync -rav --remove-source-files --files-from=<(find /home/qa/buildbot/master/packages/rhel7 -type f -mtime +30 -exec basename {} \;) /home/qa/buildbot/master/packages/rhel7 192.168.1.31:/local/raid0/buildbotpackages/packages/rhel7
... probably some error message here...
$ exit
BIG-FANCY-PROMPT%>$ _
@daily bash -c '...'