问题描述
我是 unix 新手。我的客户需要将一些数据文件通过 sftp 传输到旧系统服务器。在旧服务器中已经存在相同名称的文件。我们想要的是,当我们将 sftp 文件发送到服务器时,它会将文件的数据附加到现有文件中。 假设在旧服务器上有一个包含 10 行的文件 A.dat。现在我正在做 5 行的 sftp 文件 A.dat。所以在 sftp 之后,遗留服务器文件 A.dat 应该有 15 行。此外,如果旧系统上不存在该文件,则脚本应放置该文件。 任何快速响应都受到高度赞赏。我当前的 sftp 脚本如下所示。
#!/usr/bin/expect -d
set timeout -1
spawn sftp user@server
expect "sftp>"
send "cd /destinationpath\n"
expect "sftp>"
send "lcd /sourcepath\n"
expect "sftp>"
send "put A.dat\n"
expect "sftp>"
send "exit\n"
interact
解决方法
尝试将 -a
添加到 put
或使用
reput
。有关您的 sftp 版本,请参阅 the manual。它可能不受支持或不同。
如果它只是一个文件,我会使用 ssh 直接并附加到文件中:ssh user@server "cat >> /destinationpath/A.dat" < /sourcepath/A.dat
确保必须使用 >>
,因为 >
会覆盖您的文件。