【问题标题】:find printf what is correct format in crontab?在 crontab 中找到 printf 的正确格式是什么?
【发布时间】:2021-12-17 22:36:59
【问题描述】:

我想保存一个文件列表,我想在 cron 中做,但我不知道如何转换这个命令

echo $(find /tmp -type f -printf "%p||%s||||||") > /share/Public/serwer/test33.data

在终端中这个命令可以正常工作,但是在 cron 中是错误的,文件是空的,为什么?

我尝试在变量 %s %p 之前添加斜杠

我尝试了许多其他组合:

echo $(find /tmp -type f -printf "%p||%s||||||") > /share/Public/serwer/test33.data
echo $(find /tmp -type f -printf "%p||%s||||||") > /share/Public/serwer/test32.data
echo $(find /tmp -type f) > $TMP_DIR/test31.data
echo $(find $BACKUP_DIR -type f -printf \%p) > $TMP_DIR/test30.data
echo $(find $BACKUP_DIR -type f -printf %p) > $TMP_DIR/test28.data
echo $(find $BACKUP_DIR -type f) > $TMP_DIR/test27.data
echo $(find $BACKUP_DIR -type f -printf "ab") > $TMP_DIR/test26.data
echo $(find $BACKUP_DIR -type f -printf "||") > $TMP_DIR/test25.data
echo $(find $BACKUP_DIR -type f -printf "%p||%s\r\n") > $TMP_DIR/test01.data
echo $(find $BACKUP_DIR -type f -printf "\%p||\%s\r\n") > $TMP_DIR/test02.data
echo $(find $BACKUP_DIR -type f -printf "\%p") > $TMP_DIR/test03.data
echo $(find $BACKUP_DIR -type f -printf "\%s") > $TMP_DIR/test04.data
echo $(find $BACKUP_DIR -type f -printf "\\%s") > $TMP_DIR/test05.data
echo $(find $BACKUP_DIR -type f -printf "\\%p") > $TMP_DIR/test06.data
echo $(find $BACKUP_DIR -type f -printf "\r\n") > $TMP_DIR/test07.data
echo $(find $BACKUP_DIR -type f -printf) > $TMP_DIR/test10.data
echo $(find $BACKUP_DIR -type f -printf) > $TMP_DIR/test11.data
echo $(find $BACKUP_DIR -type f -printf "%p") > $TMP_DIR/test12.data
echo $(find $BACKUP_DIR -type f -printf "\%p") > $TMP_DIR/test13.data
echo `find $BACKUP_DIR -type f -printf "%p"` > $TMP_DIR/test14.data
echo `find $BACKUP_DIR -type f -printf "\\\\%p"` > $TMP_DIR/test15.data
echo `find $BACKUP_DIR -type f -printf \%p` > $TMP_DIR/test16.data
echo `find $BACKUP_DIR -type f -printf '\%p'` > $TMP_DIR/test17.data
echo `find $BACKUP_DIR -type f -printf '\\%p'` > $TMP_DIR/test18.data
echo `find $BACKUP_DIR -type f -printf '\\\%p'` > $TMP_DIR/test19.data
echo `find $BACKUP_DIR -type f -printf '\\\\%p'` > $TMP_DIR/test20.data
echo `find $BACKUP_DIR -type f -printf \%'s` > $TMP_DIR/test21.data
echo `find $BACKUP_DIR -type f -printf \%'p` > $TMP_DIR/test22.data
echo `find $BACKUP_DIR -type f -printf \%'p'` > $TMP_DIR/test23.data
echo `find $BACKUP_DIR -type f -printf \%'s'` > $TMP_DIR/test24.data

没有用

【问题讨论】:

  • 如何配置crontab的基本说明?
  • 你想在 crontab 中运行你的命令吗?
  • 对,如果我不添加 -printf 参数它运行正常
  • 您是否尝试过使用脚本来保存您的陈述?然后它看起来像: * * * * * /usr/bin/script.sh >> /share/Public/serwer/test33.data

标签: bash cron find printf


【解决方案1】:

这个 crontab 条目应该可以工作:

* * * * * find /tmp -type f -printf "\%p||\%s||||||\n" > /share/Public/serwer/test33.data 2>/tmp/crontab.err

【讨论】:

    【解决方案2】:

    感谢菲利普,我这样做了,我有这样的东西:

    find: unrecognized: -printf
    BusyBox v1.24.1 (2021-09-23 02:31:15 CST) multi-call binary.
    
    Usage: find [-HL] [PATH]... [OPTIONS] [ACTIONS]
    
    Search for files and perform actions on them.
    First failed action stops processing of current file.
    Defaults: PATH is current directory, action is '-print'
    
        -L,-follow  Follow symlinks
        -H      ...on command line only
        -xdev       Don't descend directories on other filesystems
        -maxdepth N Descend at most N levels. -maxdepth 0 applies
                actions to command line arguments only
        -mindepth N Don't act on first N levels
        -depth      Act on directory *after* traversing it
    
    Actions:
        ( ACTIONS ) Group actions for -o / -a
        ! ACT       Invert ACT's success/failure
        ACT1 [-a] ACT2  If ACT1 fails, stop, else do ACT2
        ACT1 -o ACT2    If ACT1 succeeds, stop, else do ACT2
                Note: -a has higher priority than -o
        -name PATTERN   Match file name (w/o directory name) to PATTERN
        -iname PATTERN  Case insensitive -name
        -path PATTERN   Match path to PATTERN
        -ipath PATTERN  Case insensitive -path
        -regex PATTERN  Match path to regex PATTERN
        -type X     File type is X (one of: f,d,l,b,c,...)
        -perm MASK  At least one mask bit (+MASK), all bits (-MASK),
                or exactly MASK bits are set in file's mode
        -mtime DAYS mtime is greater than (+N), less than (-N),
                or exactly N days in the past
        -mmin MINS  mtime is greater than (+N), less than (-N),
                or exactly N minutes in the past
        -newer FILE mtime is more recent than FILE's
        -inum N     File has inode number N
        -user NAME/ID   File is owned by given user
        -group NAME/ID  File is owned by given group
        -size N[bck]    File size is N (c:bytes,k:kbytes,b:512 bytes(def.))
                +/-N: file size is bigger/smaller than N
        -links N    Number of links is greater than (+N), less than (-N),
                or exactly N
        -prune      If current file is directory, don't descend into it
    If none of the following actions is specified, -print is assumed
        -print      Print file name
        -print0     Print file name, NUL terminated
        -exec CMD ARG ; Run CMD with all instances of {} replaced by
                file name. Fails if CMD exits with nonzero
        -exec CMD ARG + Run CMD with {} replaced by list of file names
        -delete     Delete current file/directory. Turns on -depth option
    

    【讨论】:

      【解决方案3】:

      我添加了命令查找的完整路径,现在它可以正常工作了

      /share/CACHEDEV1_DATA/.qpkg/Qapache/bin/find $BACKUP_DIR -type f -printf "%p||%s\r"
      

      感谢帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-11
        • 2015-10-16
        • 2014-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多