首页 > 解决方案 > 从 crontab 运行时预期脚本失败,但在手动运行时有效

问题描述

当我使用 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

标签: linuxshellcronexpectscp

解决方案


我找到的解决方案是改变

interact 

expect eof 
exit

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


推荐阅读