Xshell脚本

如何运行脚本

路径选择:
工具–脚本–运行–选择脚本(支持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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值