1、前言
- 其实这是一件花里胡哨的事情
- 自己平时用虚拟机跑一些linux测试,日常的习惯是克隆DHCP网络的机器,所以每次的IP都会是新的
- 于是乎,每次用MobaXterm连接新机器,都需要新建session(有的时候机器多,一个一个建立真的很烦)
4.于是就有了如下华而不实的操作
2、导出MobaXterm的session模板
- 在
User sessions
这里右键 - 选择
Export all sessions to file
,导出sessions的模板 - 导出的模板名称为:
MobaXterm Sessions.mxtsessions
(只要后缀是.mxtsessions
,就可以导入MobaXterm) - 下面我们看一下导出的模板内容
[Bookmarks] SubRep= ImgNum=42 192.168.10.2 (root)=#109#0%192.168.10.2%22%root%%-1%-1%%%22%%0%0%0%%%-1%0%0%0%%1080%%0%0%1#MobaFont%10%0%0%0%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
3、利用shell脚本生成.mxtsessions文件
#!/usr/bin/env bash set -e PWD=$(cd `dirname $0`; pwd) iphead="192.168" ipbody="10" user='root' xterm='%%-1%-1%%%22%%0%0%0%%%-1%0%0%0%%1080%%0%0%1#Consolas%14%0%0%0%15%236,236,236%0,0,0%180,180,192%0%-1%0%%xterm%-1%-1%30,30,30%54,54,54%255,96,96%255,128,128%14,177,108%24,237,147%190,190,18%222,220,18%18,150,190%27,186,233%255,77,255%255,125,255%84,204,239%142,221,244%204,204,204%204,204,204%80%24%0%1%-1%<none>%%0#0# #-1' function deploytxt (){ seq 2 254 > ${PWD}/${iphead}.${ipbody}.0-remote.txt seq -w 2 254 > ${PWD}/${iphead}.${ipbody}.0-sessionName.txt sed -i "s/^/${iphead}.${ipbody}./g" ${PWD}/${iphead}.${ipbody}.0-remote.txt sed -i "s/^/${iphead}.${ipbody}./g" ${PWD}/${iphead}.${ipbody}.0-sessionName.txt paste ${PWD}/${iphead}.${ipbody}.0-sessionName.txt ${PWD}/${iphead}.${ipbody}.0-remote.txt > xterm.txt printf "\e[1;32m ${iphead}.${ipbody}.0.txt is created in ${PWD}/\e[0m\n" } function deploymxtsessions () { cat > ${PWD}/${iphead}.${ipbody}.0.mxtsessions <<EOF [Bookmarks] SubRep= ImgNum=42 EOF echo "##sessionName## (##user##)=#109#0%##remote##%22%##user##${xterm}" > ${PWD}/xterm.example.txt printf "\e[1;32m ${iphead}.${ipbody}.0.mxtsessions example is created in ${PWD}/\e[0m\n" } function createmxtsessions () { while read xterm_line do sessionName=$(echo $xterm_line | awk '{print $1}') remote=$(echo $xterm_line | awk '{print $2}') while read xterm_example_line do echo ${xterm_example_line} | sed -e "s/##sessionName##/${sessionName}/" -e "s/##remote##/${remote}/" >> ${PWD}/${iphead}.${ipbody}.0.mxtsessions done < ${PWD}/xterm.example.txt done < ${PWD}/xterm.txt sed -i "s/##user##/${user}/g" ${PWD}/${iphead}.${ipbody}.0.mxtsessions rm -f ${PWD}/*.txt printf "\e[1;32m ${iphead}.${ipbody}.0.mxtsessions is created in ${PWD}/\e[0m\n" } function main () { deploytxt deploymxtsessions createmxtsessions } main
linux-oz6w:~ # sh mxtsessions.sh 192.168.10.0.txt is created in /root/ 192.168.10.0.mxtsessions example is created in /root/ 192.168.10.0.mxtsessions is created in /root/ linux-oz6w:~ # ll | grep mxtsessions -rw-r--r-- 1 root root 54172 Jan 8 06:27 192.168.10.0.mxtsessions -rw-r--r-- 1 root root 1122 Jan 8 06:08 mxtsessions.sh `执行脚本后,就会产生192.168.10.0.mxtsessions,从虚拟机导出到宿主机后,就可以导入到MobaXterm` `脚本里面会删除掉脚本所在路径下所有的.txt文件,一定要注意脚本的执行路径,不要误删了自己的.txt文件`
4、导入到MobaXterm
- 在
User sessions
这里右键 - 先点
New folder
(这步是为了创建一个目录,把192.168.10.0这个网段的sessions都放到一起,强迫症而已,可以不操作) - 在
192.168.10.0
这里右键 - 点
Import sessions into this folder
,选择导出的192.168.10.0.mxtsessions
,点是
即可(没有创建目录的话,点Import sessions from file
)
5、效果图
太长了,就截取一部分
更新了一下脚本,做了优化,为了看起来更舒服一点,操作起来也能舒服很多