安装工具
brew install lrzsz
安装iterm2
https://www.iterm2.com
添加脚本
#!/usr/bin/env bash
#
# iterm2-zmodem
#
# copyright (c) 2013 by Harald Lapp <harald@octris.org>
#
# AppleScript portion from:
# http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
#
#
# This script can be found at:
# https://github.com/aurora/iterm2-zmodem
#
#
# This is a re-implementation of the shell scripts "iterm2-recv-zmodem.sh" and
# "iterm2-send-zmodem.sh" found at https://github.com/mmastrac/iterm2-zmodem
#
# usage
if [[ $1 != "sz" && $1 != "rz" ]]; then
echo "usage: $0 sz|rz"
exit
fi
# send Z-Modem cancel sequence
function cancel {
echo -e \\x18\\x18\\x18\\x18\\x18
}
# send notification using growlnotify
function notify {
local msg=$1
if command -v growlnotify >/dev/null 2>&1; then
growlnotify -a /Applications/iTerm.app -n "iTerm" -m "$msg" -t "File transfer"
else
echo "# $msg" | tr '\n' ' '
fi
}
#setup
[[ $LRZSZ_PATH != "" ]] && LRZSZ_PATH=":$LRZSZ_PATH" || LRZSZ_PATH=""
PATH=$(command -p getconf PATH):/usr/local/bin$LRZSZ_PATH
ZCMD=$(
if command -v $1 >/dev/null 2>&1; then
echo "$1"
elif command -v l$1 >/dev/null 2>&1; then
echo "l$1"
fi
)
# main
if [[ $ZCMD = "" ]]; then
cancel
echo
notify "Unable to find Z-Modem tools"
exit
elif [[ $1 = "rz" ]]; then
# receive a file
DST=$(
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)&\"\")"
)
if [[ $DST = "" ]]; then
cancel
echo
fi
cd "$DST"
notify "Z-Modem started receiving file"
$ZCMD -e -y
echo
notify "Z-Modem finished receiving file"
else
# send a file
SRC=$(
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)&\"\")"
)
if [[ $SRC = "" ]]; then
cancel
echo
fi
notify "Z-Modem started sending
$SRC"
$ZCMD -e "$SRC"
echo
notify "Z-Modem finished sending
$SRC"
fi
在下面的目录创建脚本iterm2-zmodem,将上面的脚本内容添加进去或者直接wget 下载脚本
cd /usr/local/bin
wget https://raw.githubusercontent.com/aurora/iterm2-zmodem/master/iterm2-zmodem
sudo chmod +x iterm2-zmodem
trigger 配置
[外链图片转存失败(img-3npKW5ng-1566984875575)(https://note.youdao.com/yws/api/personal/file/WEB7c1ab356fafec1e19f66b9472868ca7a?method=download&shareKey=9b1f69b4e0a46bc2e3960edcd1142d7d)]
[外链图片转存失败(img-J4oqjPqS-1566984875576)(https://note.youdao.com/yws/api/personal/file/WEB0b27c310c083b1a29cd68ff5ecf73b34?method=download&shareKey=8b5c86168524d963fc86e226017611b5)]
[外链图片转存失败(img-uooniHys-1566984875578)(https://note.youdao.com/yws/api/personal/file/WEBf90f2062191db1b56b2a3ecaae7abab3?method=download&shareKey=c6214902b0189de8faa86bb9bd18fc5e)]
[外链图片转存失败(img-zTVipEQM-1566984875579)(https://note.youdao.com/yws/api/personal/file/WEBc33252815fd63ef9c12bc8b786207124?method=download&shareKey=7734cfdfc2a176434166bdffd9613c33)]
添加如下配置
Regular expression: \*\*B0100
Action: Run Coprocess
Parameters: /usr/local/bin/iterm2-zmodem sz
Regular expression: \*\*B00000000000000
Action: Run Coprocess
Parameters: /usr/local/bin/iterm2-zmodem rz
使用
上传
登录远程服务器
执行如下命令 有弹框弹出 选择3.log文件开始上传
jumpserver@master-1:~/k8s/dev$ rz
jumpserver@master-1:~/k8s/dev$ 0023be50
jumpserver@master-1:~/k8s/dev$ # Z-Modem finished sending /Users/suke/Downloads/3.log ls
jumpserver@master-1:~/k8s/dev$ ls
3.log delpod.sh desc.sh exec.sh list.sh log.sh
jumpserver@master-1:~/k8s/dev$
[外链图片转存失败(img-AU9CaK6t-1566984875579)(https://note.youdao.com/yws/api/personal/file/WEBba9d649a07ca87381fca8aceee37353f?method=download&shareKey=626dc967ec81660a3af970467c21cc5c)]
下载
登录远程服务器
执行如下命令 指定下载的文件 有弹框弹出 选下载后存放的本地目录
jumpserver@master-1:~/k8s/dev$ sz delpod.sh
jumpserver@master-1:~/k8s/dev$ # Z-Modem started receiving file **0100000063f694jumpserver@master-1:~/k8s/dev$ �**0100000063f694
# Z-Modem finished receiving file \udc8a**0100000063f694: command not found
jumpserver@master-1:~/k8s/dev$
jumpserver@master-1:~/k8s/dev$ # Z-Modem finished receiving file
[外链图片转存失败(img-PKYH9pl7-1566984875580)(https://note.youdao.com/yws/api/personal/file/WEB115b4fffe4db2648c00cd14ae54765ab?method=download&shareKey=ce123143d6ecfda4ec95ae1ef1f7d0ce)]
来源:https://blog.csdn.net/u013171997/article/details/100123710