【发布时间】: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