xshell은 자동으로 작동하도록 JS 스크립트를 작성합니다.

전망 요약, 회사에는 40개 이상의 서버가 있습니다.각 서버를 업그레이드해야 할 때 하나씩 로그인하는 것은 실제로 프로그래머의 스타일과 일치하지 않습니다. 그래서 xshell을 자동으로 작동시키는 js 자동화 스크립트를 작성했습니다.

1. 정품 xshell 설치

정품 버전 을 사용하기 시작했습니다 스크립트 실행 crt에는 문제가 없지만 xshell스크립트를 실행할 때 항상 오류가 발생합니다 분노에 맞게 무료 정품(학생용 버전)을 다시 설치했습니다 xshell다운로드 주소는 https: //www.netsarang.com/zh/all -downloads/

  1. 다운로드하려면 클릭
    여기에 이미지 설명 삽입
  2. 학생 에디션 선택
    여기에 이미지 설명 삽입
  3. 다운로드 주소 xshell받을 입력하고xftp
    여기에 이미지 설명 삽입
  4. 이메일에 있는 다운로드 주소를 클릭하여 다운로드
  5. 다운로드가 완료되면 설치하고

둘째, xshell이 ​​스크립트를 실행합니다.

1. 스크립트 작성

스크립트 형식

//固定格式,所有命令写在 Main() 方法中
function Main(){
    
    
	// xsh就是 xshell 对象
	xsh.Screen.Send("ls");
	// 发送特殊字符要使用 ACSII 编码
	xsh.Screen.Send(String.fromCharCode(13));
	//延时,防止命令没执行完
	xsh.Session.Sleep(500)}

일반적인 명령 스크립팅

일반적으로 사용되는 몇 가지 xshell 명령:

打开新会话:		xsh.Session.Open(string);
对话框提醒:		xsh.Dialog.MsgBox(string);
设置日志路径:	xsh.Session.LogFilePath = string;
开始记录日志:	xsh.Session.StartLog();
清屏函数:		xsh.Screen.Clear();
等待输入:		xsh.Screen.WaitForString(string);
输入回车:		xsh.Screen.Send(String.fromCharCode(13));
延时,单位ms:	xsh.Session.Sleep(500)

스크립트 샘플

function Main(){
    
    
	var pwds = ["123","456","789","101"];
	for (var i = 0; i < 4; i++) {
    
    
		var pwd = pwds[i];
		xsh.Screen.Send("test");
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(2000);
		xsh.Screen.Send(pwd);
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(1000);
		
		//执行一些操作
		xsh.Screen.Send("sudo -s");
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(500);
		xsh.Screen.Send(pwd);
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(500);
		
		xsh.Screen.Send("yum -y update nss nss-sysinit nss-tools openldap bind-export-libs bind-libs-lite bind-license");
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(15000);
		
		//退出
		xsh.Screen.Send("exit");
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(500);
		xsh.Screen.Send("exit");
		xsh.Screen.Send(String.fromCharCode(13));
		xsh.Session.Sleep(500);
	}
}

2. 스크립트 실행

xshell 실행 js 스크립트 작업: 도구 모음에서 클릭 --> 스크립트 --> 실행

추천

출처blog.csdn.net/zyx1260168395/article/details/118150739