【问题标题】:Expect script fails when running from crontab but works when run manually从 crontab 运行时预期脚本失败,但在手动运行时有效
【发布时间】:2021-03-12 16:08:34
【问题描述】:

当我使用 crontab 运行这个 shell 脚本时,它不起作用 但是如果我手动操作的话。

我缺少要配置的环境变量,或者需要做一些额外的工作才能使其正常工作。

感谢您的帮助。

脚本:/process/files/test_expect_cron.sh

remoteuser="user"
remotehost="10.77.88.111"
remotepass="pass1"

cd /process/files
pathfiles="/process/files"
remote_files="/data/20201129/*FILES_20201129*"

cat > expect.dat << EOF
    spawn scp -r $remoteuser@$remotehost:$remote_files $pathfiles/.
    expect "*?assword*"
    send "$remotepass\r"
    interact
EOF
expect "expect.dat"

Crontab

40      11      *       *       * sh /process/files/test_expect_cron.sh

【问题讨论】:

  • 是否允许cron用户在/process/files中写入文件? /process/files/expect.dat 文件是否包含您认为应该包含的内容? scp 在 cron 环境的 PATH 中吗?期望在那个PATH中吗?另见stackoverflow.com/tags/cron/info
  • 我遇到了这个确切的问题
  • @JoeBanks 我找到的解决方案是将 ``` interact ``` 更改为 ``expect eof exit ``` 如果有人有更好的解决方案,发布它
  • @Tomas :在脚本中使用interact 有什么意义,该脚本在后台运行并且没有任何人可以与之交互?

标签: linux shell cron expect scp


【解决方案1】:

我找到的解决方案是改变

interact 

expect eof 
exit

如果有人有更好的解决方案,请发布

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-14
    • 2021-05-01
    • 1970-01-01
    • 2022-01-19
    • 2017-12-07
    • 2011-10-03
    • 2016-12-18
    • 2013-10-18
    相关资源
    最近更新 更多