【问题标题】:In FTP command mode, how do I redirect command line and the result when using shell script using here document to let ftp command read stdin在 FTP 命令模式下,如何重定向命令行和使用 shell 脚本使用这里文档让 ftp 命令读取标准输入时的结果
【发布时间】:2019-11-16 08:27:08
【问题描述】:

我正在尝试编写实现 FTP 命令读取此处文档的 shell 脚本。

如何重定向 ftp 命令行和 FTP 服务器返回的结果?

我当前的脚本在下面

#!/bin/bash
ftp -ivn <<EOF |& tee ftplog.text
open <myFtpserver>
user <username> <password>
pwd
ls -l MYFILE_*
bye
EOF

此代码输出 ftp 服务器的响应,但将 ftp 命令输出到 ftplog.txt。 如何重定向两者?

感谢您的帮助

【问题讨论】:

  • &gt;替换|&amp; tee?
  • 在此处的文档中添加了debug,它显示了我的命令行。

标签: linux bash shell ftp


【解决方案1】:

您应该以这种方式创建脚本:

#!/bin/bash
ftp -ivn >ftplog.text  <<EOF 
open <myFtpserver>
user <username> <password>
pwd
ls -l MYFILE_*
bye
EOF

重定向到命令,而不是内联块

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多