我正在尝试制作一个 bash 脚本来发送文件。在终端中运行此命令时,我收到错误:
第 4 行:警告:此处文档在第 2 行由文件结尾分隔(需要 `EOF
这是脚本:
#!/bin/bash
sshpass -p 'password' scp /dir/sub/sub/sub/sub/file.csv [email protected]:/ <<-EOF
quit
EOF
它将发送文件,但是当我尝试使用 crontab 运行脚本时,它不会运行。我需要改变什么?而且我只能使用密码而不能使用密钥。
我测试了以下代码是否可以工作:
cron-job--scp-files-locally.sh
#!/bin/bash
# create an ind file with current minute timestamp
touch $(date +%Y-%m-%d_%H%M).ind
# copy all ind files to /tmp
/usr/bin/sshpass -p 'greatPassword' /usr/bin/scp *.ind metoo@localhost:/tmp
# remove all ind files
rm -f *.ind
* * * * * /home/cfrm/cron-job--scp-files-locally.sh
ls -1 /tmp/*ind
/tmp/2023-12-11_1619.ind
/tmp/2023-12-11_1620.ind
/tmp/2023-12-11_1621.ind
#!/bin/bash
/usr/bin/sshpass -p 'greatPassword' /usr/bin/scp /dir/sub/sub/sub/sub/file.csv [email protected]:/