1、将xshell会话导出
我这里将所有ssh链接都导出至桌面上了,自动生成了一个Sessions 文件夹
2、脚本
- 新建文件
x2m.sh ,将下面的脚本保存到文件中 - 脚本中修改
dir 的值,xshell 导出的Sessions 文件夹的路径,我这里是放在桌面的,所以路径是dir='/c/Users/dling/Desktop/Sessions' (注意这里的路径和windows的路径有点差异C:\Users\dling\Desktop\Sessions )
我这里使用的是Git Bash
脚本如下:
: '
目录结构:
Sessions
root
a.xsh
b.xsh
测试
华东
a.xsh
b.xsh
华北
c.xsh
d.xsh
开发
华东
aa.xsh
bb.xsh
华北
cc.xsh
dd.xsh
folder.ini
'
dir='/c/Users/dling/Desktop/Sessions'
parentDir=''
declare -i imgNum=42
declare -i J=0
command1="ls -l \"\$1\"|awk '{\$1=\$2=\$3=\$4=\$5=\$6=\$7=\$8=\"\"; print \$0}'|sed '1d;s/^\s\+//g;s/\s/??/g'"
command2="echo \"\$fileOrDir\" | sed 's:??: :g'"
parseXshFile() {
declare -i index=0
local parentDirPath=$2
local parentDirOrFile=$3
echo "\$1=$1"
echo "\$2=$parentDirPath"
echo "\$3=$3"
echo "ImgNum=$imgNum"
if [ -d "$1" ]; then
for fileOrDir in `eval $command1`
do
local evalCommand2="`eval $command2`"
evalCommand2=${evalCommand2%%'/'*}
echo "====$1/$evalCommand2"
if [ -f "$1/$evalCommand2" ]; then
echo "===================="
parseXshFile "$1/$evalCommand2" "$1" "$evalCommand2"
fi
done
let "imgNum=(--imgNum)"
for fileOrDir in `eval $command1`
do
local evalCommand2="`eval $command2`"
evalCommand2=${evalCommand2%%'/'*}
if [ -d "$1/$evalCommand2" ]; then
let "J=(++J)"
echo -e "\n" >> $dir/export.txt
echo "[Bookmarks_$J]" >> $dir/export.txt
echo "SubRep="$3\\$evalCommand2"" >> $dir/export.txt
echo "ImgNum=$4" >> $dir/export.txt
parseXshFile "$1/$evalCommand2" "$1" "$evalCommand2" $4
fi
done
elif [ -f "$1" ]; then
ls "$1" | grep xsh
if [ $? -eq 0 ]; then
local filename="$1"
local username=`iconv -f utf-16le -t utf-8 "$filename"|grep ^UserName|cut -f 2 -d '='`
local host=`iconv -f utf-16le -t utf-8 "$filename"|grep ^Host|cut -f 2 -d '='`
local port=`iconv -f utf-16le -t utf-8 "$filename"|grep ^Port|cut -f 2 -d '='`
echo "`echo ${parentDirOrFile%%'.xsh'*}`=#109#0%$host%$port%$username%%-1%-1%%%%%0%0%0%%%-1%0%0%0%%1080%%0%0%1#MobaFont%10%0%0%-1%15%236,236,236%30,30,30%180,180,192%0%-1%0%%xterm%-1%-1%_Std_Colors_0_%80%24%0%1%-1%<none>%%0%0%-1#0# #-1" >> $dir/export.txt
fi
fi
echo
}
echo "[Bookmarks]" >> $dir/export.txt
echo "SubRep=" >> $dir/export.txt
echo "ImgNum=$imgNum" >> $dir/export.txt
let "imgNum=(--imgNum)"
parseXshFile $dir "" "" $imgNum
iconv -f utf-8 -t gbk "$dir/export.txt" > "$dir/import.mxtsessions"
3、运行脚本x2m.sh
执行命令:sh x2m.sh 执行结束会在Sessions目录下生成文件import.mxtsessions
4、MobaXterm 导入文件import.mxtsessions
这就不用说了吧。。。
写作不易,如果文章对你有帮助,还请点个赞喔 ,让更多的人看到 (●’?’●)
|