【发布时间】:2019-11-25 13:53:32
【问题描述】:
以下 crontab 行(在 CentOS 7.6 上)
@daily 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
失败,并向我发送以下电子邮件:
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]
看了rsync的main.c的源码,没看到1567行的相关性:
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();
此外,当我从 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 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$
关于如何调试此问题的任何想法?
【问题讨论】:
-
cron 使用
/bin/sh运行命令,它不支持交互式shell 的所有花哨语法。用<(...)替换命令不是标准sh语言的一部分。 -
您可以将
rsync命令放在一个shell 脚本中(以指定bash 的shebang 行开头——#!/bin/bash或#!/usr/bin/env bash),然后从cron运行该脚本。 -
感谢@Wumpus 的回答。如果您将其放在答案中,我可以为您的 StackOverflow 声誉做出贡献。
-
只是加入。尝试用完整路径替换 rsync。通常是 (/usr/bin/rsync)。