【问题标题】:Using SCP command to download logs from Linux server to local machine使用 SCP 命令将日志从 Linux 服务器下载到本地机器
【发布时间】:2021-11-15 14:46:39
【问题描述】:

如何使用“SCP”命令将最后 10 行访问日志从远程服务器下载到本地计算机以仅显示。我尝试使用 scp 管道 tail 命令,但无法下载最后 10 行。

【问题讨论】:

  • “无法下载最后 10 行”是什么意思?什么错误?
  • 如果 scp 由于某种原因无法正常工作,您也可以ssh user@host tail -n10 /path/to/logfile > ./mylocallogfile
  • 它实际上是在下载整个 access.log 文件。但我只需将该日志文件的最后 10 行下载到我的本地计算机。
  • 然后 ssh 命令将实现这一点。它在远程服务器上调用tail
  • 谢谢。 ssh 命令有效,我可以使用该命令仅下载最后 10 行日志。

标签: amazon-web-services amazon-ec2 scp tail


【解决方案1】:

你可以试试daggy

使用要传输的文件和要从中传输的远程服务器创建源配置 (heads.yaml):

    aliases:  
        - &my_commands
            file1:
                exec: haed -n 10 file1
                extension: log
            file2:
                exec: head -n 10 file2
                extension: log
            
        - &ssh_auth
            user: {{env_USER}}
            passphrase: {{env_PASSWORD}}
                
    sources:
        localhost:
            type: local
            commands: *my_commands
        remotehost:
            host: 192.168.1.9
            type: ssh2
            parameters: *ssh_auth
            commands: *my_commands
        remotehost2:
            host: 192.168.1.10
            type: ssh2
            parameters: *ssh_auth
            commands: *my_commands

奔跑吧:

    daggy heads.yaml

【讨论】:

    猜你喜欢
    • 2016-02-08
    • 2018-01-28
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多