cmd使用ssh连接Linux脚本

前言

在开发过程中,由于MobaXterm,我不知道怎么分页(不是屏内分页),用crtl+Tab,用起来不习惯,主要是MobaXterm连接了多个服务器,切换起来很麻烦。我是比较习惯使用alt+Tab,于是我就想着用cmd,连接ssh,当开发过程需要看日志,我就只开一个cmd连接ssh,但是每一次cmd都要重新连接,(为什么不创建秘钥,因为开发服务器,经常,,所以不创建秘钥)于是我写了个脚本,在cmd直接运行就可以连接服务器,并且查看某个日志。

可直接在打开cmd的默认路径下(我的是c:/user/user)创建一个 .vbs 的文件

sh 复制代码
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 1500
' 下面的 + 号,表示输入法切换,不需要切换输入法的可以不要 '
WshShell.SendKeys "+"    
' 这里ssh连接,默认端口为22,有其他端口的可以在后面加上 -p 端口号 '
WshShell.SendKeys "ssh 用户名@你的ip"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "服务器密码"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "tailf /sf/log/today/你的日志名称"
WshShell.SendKeys "{ENTER}"

编写完vbs脚本后,即可win+R,然后执行脚本文件(因为文件创建在打开cmd的默认路径下,所以很方便),即可连接上服务器,查看日志。

当有多个服务器需要看日志,那么每一次都需要修改vbs脚本比较麻烦,那就在上面的代码修改一点点
sh 复制代码
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 1500
usernameInput = InputBox("Enter your username:")
ipInput = InputBox("Enter your ip:")
passwordInput = InputBox("Enter your password:")
WshShell.SendKeys "ssh " & usernameInput & "@" & ipInput
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys passwordInput
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "cd /sf/log/today"
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "tailf /sf/log/today/你的日志文件"
WshShell.SendKeys "{ENTER}"

这个脚本执行起来,就会提出提示框,让你填写你要查看的服务器

哈哈哈,看起来没什么用,但是还是方便了那么一点点。

相关推荐
sulikey2 小时前
Linux ext2文件系统结构
linux·操作系统·文件系统·linux文件系统·ext2·ext2文件系统
白菜欣3 小时前
Linux — 进程控制
android·linux·运维
JoneBB3 小时前
ABAP Webservice连接
运维·开发语言·数据库·学习
皮卡狮4 小时前
Linux开发专属工具
linux
weixin_421725264 小时前
Linux 编程语言全解析:C、C++、Python、Go、Rust 谁更强?
linux·python·go·c·编程语言
Tolalal4 小时前
Vmware Ubuntu虚拟机扩容
linux·运维·ubuntu
咚为5 小时前
比AccessLog更全面的原生Nginx 日志记录
运维·nginx·junit
我星期八休息5 小时前
Linux系统编程—基础IO
linux·运维·服务器·c语言·c++·人工智能·算法
Shingmc35 小时前
【Linux】数据链路层
linux·服务器·网络
a752066285 小时前
零基础实操:小龙虾 AI OpenClaw 接入 Kimi 详细步骤
运维·服务器