zoukankan      html  css  js  c++  java
  • mac中使用rz,sz上传文件

    公司有几台服务器是使用跳板机登录上去的,离职的同事也没有交接,现在我要去发代码,也不知道以前他们怎么发上去的,开始以为是用git直接搞的,结果发现不是的,所以最后使用的是Mac中配合iTerm2使用rz,sz上传/下载文件。

    安装rz / sz

    使用brew安装

    brew install lrzsz
    

    安装完成后,在/usr/local/bin目录下建两个文件

    /usr/local/bin/iterm2-send-zmodem.sh 文件内容如下:

    #!/bin/bash
    # Author: Matt Mastracci (matthew@mastracci.com)
    # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
    # licensed under cc-wiki with attribution required
    # Remainder of script public domain
    
    osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
    if [[ $NAME = "iTerm" ]]; then
        FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script ("echo "&(quoted form of POSIX path of thefile as Unicode text)&"")"`
    else
        FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script ("echo "&(quoted form of POSIX path of thefile as Unicode text)&"")"`
    fi
    if [[ $FILE = "" ]]; then
        echo Cancelled.
        # Send ZModem cancel
        echo -e \x18\x18\x18\x18\x18
        sleep 1
        echo
        echo # Cancelled transfer
    else
        /usr/local/bin/sz "$FILE" -e -b
        sleep 1
        echo
        echo # Received $FILE
    fi
    

    /usr/local/bin/iterm2-recv-zmodem.sh 文件内容如下:

    #!/bin/bash
    # Author: Matt Mastracci (matthew@mastracci.com)
    # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
    # licensed under cc-wiki with attribution required
    # Remainder of script public domain
    
    osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
    if [[ $NAME = "iTerm" ]]; then
        FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script ("echo "&(quoted form of POSIX path of thefile as Unicode text)&"")"`
    else
        FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script ("echo "&(quoted form of POSIX path of thefile as Unicode text)&"")"`
    fi
    
    if [[ $FILE = "" ]]; then
        echo Cancelled.
        # Send ZModem cancel
        echo -e \x18\x18\x18\x18\x18
        sleep 1
        echo
        echo # Cancelled transfer
    else
        cd "$FILE"
        /usr/local/bin/rz -E -e -b
        sleep 1
        echo
        echo
        echo # Sent -> $FILE
    fi
    

    文件添加完成后,给这两文件授于可执行权限

    chmod +x /usr/local/bin/iterm2-send-zmodem.sh
    chmod +x /usr/local/bin/iterm2-recv-zmodem.sh
    
    

    好了,上面的准备工作已经完了,接下来配置iTerm2

    点击 "Edit"配置 Triggers, 通过匹配正则触发操作

    Regular expression: rz waiting to receive.**B0100 
    Action: Run Silent Coprocess 
    Parameters: /usr/local/bin/iterm2-send-zmodem.sh
    
      
    Regular expression: **B00000000000000 
    Action: Run Silent Coprocess 
    Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
    
    

    配置完成后,就能使用rz,sz上传/下载文件了,不过,我在Mac中按照上面的配置,去使用rz,sz会卡住,没有任何弹出框出来选择文件上传,后面发现还需要安装一个zssh,用ssh还不行。

    brew install zssh
    

    安装完zssh后,就可以了,但是还是要注意,如果使用expect类的脚本,后面还是弹不出,至少我遇到的就是这样,最终我就直接搞了个bash文件,里面就一行

    zssh -i /tmp/rz.pem lc@12.8.10.79
    

    这样通过ssh到机器10.79这个跳板机后,再通过跳板机连接到服务器后,就能直接使用rz,sz了。

    所以如果遇到配置完成后,弹不出来的就要注意看下有没有安装zssh,而且尽量脚本简单些。

  • 相关阅读:
    HTML DOM Body vLink 属性
    HTML <dialog> 标签
    JavaScript atan() 方法
    HTML URL 编码参考手册
    HTML DOM dir 属性
    CSS3 小黄人案例
    CSS 之 圣杯布局&双飞翼布局
    CSS3 渐变
    浏览器前缀
    CSS3 弹性盒布局
  • 原文地址:https://www.cnblogs.com/smartrui/p/13082193.html
Copyright © 2011-2022 走看看