如何运行脚本

路径选择:
工具–脚本–运行–选择脚本(支持py,js,vb三种脚本)

Xshell帮助文档

查看Xshell脚本帮助文档,帮助文档打开方式:

方式一,选择帮助–Xshell帮助–Using Scripts–Script API
方式二,打开Xshell的安装目录,手动打开帮助文档

js脚本

示例一:定期输入命令、保存屏幕打印

//文件名称 ls_l.js
function Main()
{
	/* 设置屏幕同步 */
	xsh.Screen.Synchronous = true;

	/* 开始记录日志 */
	xsh.Session.LogFilePath = "C:\Users\mayue6\Desktop\save_xshell.log";
	xsh.Session.StartLog();

	while (1) {
		/* 向终端发送消息 */
		xsh.Screen.Send("ls -l");

		/* 向终端发送回车语句 */
		xsh.Screen.Send(String.fromCharCode(13));

		/* 延时等待2秒 */
		xsh.Session.Sleep(2000);
	}
}

示例二:等待指定字符串出现

WaitForString函数参数不能有空格
问题:屏幕中有对应的字符串就会不断的刷打印,没法重新开始检测(不要之前的数据)

function Main()
{
	/* 设置屏幕同步 */
	xsh.Screen.Synchronous = true;
	xsh.Session.Sleep(1000);

	while (1) {
		/* 等待固定字符串 */
		xsh.Screen.WaitForString("PHY!!!!!!");
		// xsh.Screen.Send("ls -l");
		// xsh.Screen.Send(String.fromCharCode(13));

		xsh.Session.Sleep(1000);
		/* 向终端发送Ctrl+u语句 */
		xsh.Screen.Send(String.fromCharCode(21));
		xsh.Screen.Send(String.fromCharCode(21));

		xsh.Screen.Send("pri");
		xsh.Screen.Send(String.fromCharCode(13));

		/* 延时等待2秒 */
		xsh.Session.Sleep(2000);
	}
}

py脚本

其他文档

Xshell设置运行自动化脚本
https://www.cnblogs.com/li150dan/p/11038216.html

xshell调用js脚本开发
https://blog.csdn.net/xuezoutianya/article/details/81605604

xshell 运行脚本的部分总结
https://blog.csdn.net/chuangyiwen1827/article/details/101011185

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐