iterm堡垒机rz和sz环境配置(转载)

适用人群:更灵活使用iterm上传和下载

1、首先要有iTerm2

iTerm2官网下载地址:iTerm2下载链接

2、本地安装lrzxz

brew install lrzsz 

3、下载iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh脚本文件

    见附件

iterm2-send-zmodem.sh

#!/bin/bash
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
    /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo \# Received $FILE
fi

iterm2-recv-zmodem.sh

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"
    /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi

4、将这两个脚本文件保存到/usr/local/bin/ 路径下,cd到该目录下为其添加可执行权限。

chmod +x iterm2-send-zmodem.shchmod +x iterm2-recv-zmodem.sh

5、iterm2 添加 triggers

打开“Preferences”面板->Profiles选项卡->Advanced->Triggers(点击Edit即可)

Regular expression: \*\*B0100Action: Run Silent CoprocessParameters: /usr/local/bin/iterm2-send-zmodem.shRegular expression: \*\*B00000000000000Action: Run Silent CoprocessParameters: /usr/local/bin/iterm2-recv-zmodem.sh

见下图

1635908893384-398.png

一切就绪就可以愉快地使用了。

再啰嗦一嘴,在远程服务器端也需要事先安装lrzsz。

yum -y install lrzsz

附rz sz命令使用方法

To send a file to a remote machine:    Type "rz" on the remote machine    Select the file(s) on the local machine to send    Wait for the coprocess indicator to disappear

The receive a file from a remote machine

    Type "sz filename1 filename2 … filenameN" on the remote machine

    Select the folder to receive to on the local machine

    Wait for the coprocess indicator to disappear

参考:iTerm2安装lrzsz命令出错解决 - 简书

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值