怎么用脚本自动在xshell输入命令
时间: 2023-06-10 09:08:00 浏览: 215
你可以使用 Python 或者其他脚本语言来实现在 Xshell 中自动输入命令。以下是一个使用 Python 在 Xshell 中自动输入命令的示例代码:
```python
import time
import os
# 定义 Xshell 连接信息
host = 'your_host'
username = 'your_username'
password = 'your_password'
# 打开 Xshell
os.startfile('C:/Program Files (x86)/NetSarang/Xshell 7/Xshell.exe')
# 等待程序启动
time.sleep(5)
# 自动输入用户名和密码
os.system(f'echo {username} >> C:/temp/cmd.txt')
os.system(f'echo {password} >> C:/temp/cmd.txt')
# 自动输入命令
os.system(f'echo command1 >> C:/temp/cmd.txt')
os.system(f'echo command2 >> C:/temp/cmd.txt')
# 执行命令
os.system(f'putty.exe -ssh {host} -l {username} -pw {password} -m C:/temp/cmd.txt')
# 删除命令文件
os.remove('C:/temp/cmd.txt')
```
该脚本会启动 Xshell,等待 5 秒钟后自动输入用户名和密码,并执行指定的命令。你可以根据需要修改代码中的连接信息和命令内容。
阅读全文
相关推荐















