【问题标题】:Why does ssh find -exec does not work in script?为什么 ssh find -exec 在脚本中不起作用?
【发布时间】:2019-10-26 19:05:00
【问题描述】:

我需要在带有 ssh 的脚本中使用 find 命令并一起查找。像这样的:

expect -c "
    spawn ssh user@host \"find api -type f -name *.html -mtime +30 -exec rm -rf {} \;\"
    expect {
        \"*password\" {set timeout 300; send \"mypassword\r\";}
          }
    expect eof"

我明白了

find: missing argument to `-exec'

对可能导致此问题的原因或如何解决此问题有任何想法吗?谢谢

【问题讨论】:

标签: shell ssh find exec expect


【解决方案1】:

我发现 heredocs 有助于避免引用地狱

expect << 'END_EXPECT'
    spawn ssh user@host "find api -type f -name *.html -mtime +30 -exec rm -rf {} \;"
    expect "*password" {set timeout 300; send "mypassword\r"}
    expect eof
END_EXPECT

【讨论】:

    猜你喜欢
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    • 2013-11-18
    • 1970-01-01
    • 2016-05-17
    • 2018-03-23
    • 1970-01-01
    相关资源
    最近更新 更多