批处理命令,自动登陆redis服务器,执行清空缓存操作

1、手写一个VB执行文件 “temp.vbs”,如存放到 c:\temp.vbs 路径下。

' * Company: ChangYouTianXia
' * @author sunyf
' * date: 2013-6-28 下午6:08:51
' * @version 1.0
':::::::::远程登陆后执行相关命令::::::::::
dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.run"cmd"
WScript.Sleep 10
WshShell.AppActivate"c:\windows\system32\cmd.exe"
WshShell.SendKeys"telnet *.*.*.* 6379{ENTER}"
WshShell.SendKeys"echo '========= telnet *.*.*.* 6379'{ENTER}"
WshShell.SendKeys"dbsize{ENTER}"
WScript.Sleep 10
WshShell.SendKeys"{ENTER}flushall{ENTER}"
WScript.Sleep 10
WshShell.SendKeys"{ENTER}dbsize{ENTER}"
WScript.Sleep 10
WshShell.SendKeys"{ENTER}quit{ENTER}"
WScript.Sleep 2000
WshShell.SendKeys"exit"
WshShell.SendKeys"{ENTER}"

 2、在任意路径创建一个bat可执行文件 “clear redis.bat”。 

::::::::::* Company: ChangYouTianXia
::::::::::* @author sunyf
::::::::::* date: 2013-6-28 下午6:08:51
::::::::::* @version 1.0
::::::::::远程登陆后执行相关命令::::::::::
@call c:\temp.vbs

 3、点击bat文件,即执行vbs中的相关指令。

批处理命令,自动登陆redis服务器,执行清空缓存操作
 


如果想简单一点,一个指令文件可完成:

 1、在任意路径创建一个bat可执行文件 “clear redis.bat”。

::::::::::* Company: ChangYouTianXia
::::::::::* @author sunyf
::::::::::* date: 2013-6-28 下午6:08:51
::::::::::* @version 1.0
::::::::::远程登陆后执行相关命令::::::::::
@del	c:\temp.vbs
@echo	dim WshShell	>>c:\temp.vbs
@echo	Set WshShell = WScript.CreateObject("WScript.Shell")	>>c:\temp.vbs

::@echo	远程登陆[*.*.*.* 6379],执行命令....
@echo	WshShell.run"cmd"	>>c:\temp.vbs
@echo	WScript.Sleep 10	>>c:\temp.vbs
@echo	WshShell.AppActivate"c:\windows\system32\cmd.exe"	>>c:\temp.vbs
@echo	WshShell.SendKeys"telnet *.*.*.* 6379{ENTER}"	>>c:\temp.vbs
@echo	WshShell.SendKeys"echo '========= telnet *.*.*.* 6379'{ENTER}"	>>c:\temp.vbs
@echo	WScript.Sleep 100	>>c:\temp.vbs
@echo	WshShell.SendKeys"dbsize{ENTER}"	>>c:\temp.vbs
@echo	WScript.Sleep 100	>>c:\temp.vbs
@echo	WshShell.SendKeys"{ENTER}flushall{ENTER}"	>>c:\temp.vbs
@echo	WScript.Sleep 100	>>c:\temp.vbs
@echo	WshShell.SendKeys"{ENTER}dbsize{ENTER}"	>>c:\temp.vbs
@echo	WScript.Sleep 100	>>c:\temp.vbs
@echo	WshShell.SendKeys"{ENTER}quit{ENTER}"	>>c:\temp.vbs
@echo	WScript.Sleep 100	>>c:\temp.vbs
@echo	WshShell.SendKeys"exit"	>>c:\temp.vbs

 2、点击bat文件,即可。

你可能感兴趣的:(telnet,bat)