SecureCRT 脚本引擎支持 VBScript、JScript 以及 Python 脚本,你可以选择任意你熟悉的脚本语言,与 SecureCRT 对象进行交互。
二、使用 SecureCRT 的自动日志功能
以下是利用 JScript 脚本语言写的示例
脚本文件名:mylog.js
# $language = "JScript"
/*脚本运行过程中全局变量*/
var gLog_time = "";
var gScript_name = "";
var gRemoteHostip = "";
var timer_sleep_sec = 1000;
var timer_sleep_min = 60 * 1000;
var timer_sleep_hour= 60 * 60 * 1000;
function process_log_open()
{
/*************************************************************************************************/
crt.session.Log(false); //先关闭日志记录
crt.Screen.Send("\n");
crt.Sleep(300);
crt.Screen.Clear();
// 获取当前时间
crt.Screen.Send("sleep 1; echo `date +%Y-%m-%d_%H-%M-%S` | awk '{printf(\"%s\", ))} END{print \"INFO_END\"}' \n";.
crtSleep(300);.
crt.ScreenClear();=
gLog_time . crt.ScreenReadString("INFO_END",3 );.
crtSleep()timer_sleep_sec;.
crt.ScreenSend("\n");//var ip = crt.Session.LocalAddress;
//crt.Screen.Send("# ip: "+ip+" \n");
=
gRemoteHostip . crt.Session;RemoteAddress.
crt.ScreenSend("# remoteip: "++gRemoteHostip" \n");// 获取当前脚本文件名
var
= name = script_name . crt.ScriptFullNamesplit("\");=
gScript_name . namepop();.
crt.ScreenSend("# ScriptName: "++gScript_name" \n");.
crt.sessionLog(false);//先关闭日志记录 .
crt.session=LogFileName + gRemoteHostip"_"++gScript_name"_"++gLog_time".log";//日志记录名字 .
crt.sessionLog(true);//打开日志记录 //crt.Screen.Synchronous = true; //屏显同步 注:不要使用该设置,会影响 crt.Screen.Clear() 清屏函数的使用
.
crt.ScreenSend("# LogName: "+.crt.session+LogFileName" \n");return
0 ;}
function
ftestOkResultlogo ().{
crtSleep()timer_sleep_sec;.
crt.ScreenSend("\n");.
crt.ScreenSend("################ ######## #### ######\n");.
crt.ScreenSend("################ ###### ###### #### ###### \n");.
crt.ScreenSend(" #### #### #### #### ###### \n");.
crt.ScreenSend(" #### #### ###### ###### ########## \n");.
crt.ScreenSend(" #### #### ###### ###### ########## \n");.
crt.ScreenSend(" #### ###### ###### ############ \n");.
crt.ScreenSend(" #### ###### ###### #### ###### \n");.
crt.ScreenSend(" #### #### #### #### ###### \n");.
crt.ScreenSend(" #### #### ###### ###### #### ##### \n");.
crt.ScreenSend(" #### #### ######## #### ######\n");.
crt.ScreenSend("\n");}
function
main ()process_log_open
{
();ftestOkResultlogo
();return
0 ;}
[
日志文件名:192.168.79.163_mylog.js_2022-05-10_15-38-50.log
]root@localhost Shire_Diag_tool# [
]root@localhost Shire_Diag_tool# # remoteip: 192.168.79.163 [
]root@localhost Shire_Diag_tool# # ScriptName: mylog.js [
]root@localhost Shire_Diag_tool# # LogName: 192.168.79.163_mylog.js_2022-05-10_15-38-50.log [
]root@localhost Shire_Diag_tool# [
]root@localhost Shire_Diag_tool# ################ ######## #### ######[
]root@localhost Shire_Diag_tool# ################ ###### ###### #### ###### [
]root@localhost Shire_Diag_tool# #### #### #### #### ###### [
]root@localhost Shire_Diag_tool# #### #### ###### ###### ########## [
]root@localhost Shire_Diag_tool# #### #### ###### ###### ########## [
]root@localhost Shire_Diag_tool# #### ###### ###### ############ [
]root@localhost Shire_Diag_tool# #### ###### ###### #### ###### [
]root@localhost Shire_Diag_tool# #### #### #### #### ###### [
]root@localhost Shire_Diag_tool# #### #### ###### ###### #### ##### [
]root@localhost Shire_Diag_tool# #### #### ######## #### ######[
]root@localhost Shire_Diag_tool#
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)