DOS batch operation telnet to implement automatic Telnet operation

Source: Internet
Author: User

Just took part in the work soon, the project manager released the task to me, the beginning of a few days still a little new sense, but play for a long time, on those few orders, really don't mean, but still have to do, all bored dead. I am lazy, tried n long a lazy man tool finally out. Write it out for everyone to share.

------------------------------------------------------------------------------------------------------

Configuration of my work environment:

Development tools: Ecplise

Database: oracle10g

Test server: HP-UX + Weblogic9.2

since dozens of people developed at the same time, we first update our own code to the CVS server, and then into the war package, with FTP to the test machine, decompression, and restart the WebLogic. Deploy to the test machine (requires that the war pack be decompressed under the test machine).

-------------------------------------------------------------------------------------------------------

Let's take a look at my general job scheduling scripts

FILE:autoRefresh8.bat

@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The:::::::::::: To set the 10.1.18.8 server configuration::: £ º::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Server Address
Set url=10.1.18.8
:: Remote login username, password
Set Userid=weblogic
Set Password=weblogic
:: Logged in home directory
Set Homedir=/weblogic
:: directory and filename to execute shell script
Set Shdir=/weblogic/syang
:: To extract and stop the server shell script file name
Set stopshfilename=stopandextract.sh
:: Start the server's shell script filename
Set startshfilename=startadmin.sh
:: Decompression Wait time
Set times=25000
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::-:::::: Stop the server, and extract the latest War package:::::::;;::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Echo stops the server and unzip the deployment file ...
Call Stopandextract.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
To:::::::::::: To upload the latest jar kits and related profiles::: £ º::::: £ º:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo from the local upload jar package and configuration file to 10.1.18.8 ...
Call Ftp_8.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::-:::::::;::;:::; Start the server::::::::::::;:.:::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Echo Starts server ...
Call Startadmin.bat

Telnet to the server and unzip the war package

FILE:stopAndExtract.bat

@echo off
Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::
The:::::::::::;:::;::;:-------:
::::::::::::::::::::::::::::::::::::::::::::::
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "%userid%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "%password%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
::::::: £ º:::: £ º:: £ º:: £ º:::
::::::::::::::::::::::::::::::::::::::::::::::::
Echo Sh. SendKeys "CD%homedir%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
The::::::::::: To enter the automatic script directory:::::::
::::::::::::::::::::::::::::::::::::::::::::::::
Echo Sh. SendKeys "CD%shdir%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
::::::: Automatic Decompression:::-------:::::::::
::::::::::::::::::::::::::::::::::::::::::::::::
rem echo stops WebLogic and extracts the war package
Echo Sh. SendKeys "sh%stopshfilename% {ENTER}" >>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::;:--------decompression, wait time:
::::::::::::::::::::::::::::::::::::::::::::::::
Echo Wscript.Sleep%times%>>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
::::::-::::: To exit the Shell:;:::;:::;::
::::::::::::::::::::::::::::::::::::::::::::::::
Echo Sh. SendKeys "Exit{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Quit{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs
::::::::::::::::::::::::::::::::::::::::::::::::
The:::::::::::::--::;:::;::;::
::::::::::::::::::::::::::::::::::::::::::::::::
Start Telnet%url%
:: Cscript Telnet_tmp.vbs
::d El Telnet_tmp.vbs

because the test server has two, and the two servers need a special jar package, and the internal content is not exactly the same, so can only be uploaded separately

FILE:ftp_8.bat

@echo off
Ftp-ns:ftp_10.1.18.8.ftp

Automatic FTP Scripts

file:ftp_10.1.18.8.ftp

Open 10.1.18.8
User WebLogic
Weblogic
Cd/weblogic/bea/user_projects/domains/base_domain/cebplms/web-inf/lib
Delete Ceboci.jar
LCD D:/workspace/jar
Binary
Put Ceboci8.jar
Rename Ceboci8.jar Ceboci.jar
Ascii
Cd..
Delete Amarsoft.xml
Put Amarsoft.xml
Bye
Quit

Start Server Script

File:startAdmin.bat

@echo off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::.:::::::;:::::::;:::::::::::;::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "%userid%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "%password%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::,:::: To enter the home directory, to start the service:: £ º-:::::,/:---
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Echo Sh. SendKeys "CD%homedir%{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "sh%startshfilename% {ENTER}" >>telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::;:::::::;::;:::::.:::::;:::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Exit{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Quit{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
The::::::::::::::;:::::::::::::.:::::::.::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Start Telnet%url%
cscript Telnet_tmp.vbs
::d El Telnet_tmp.vbs

Finally, attach the shell script that stops the WebLogic server and extracts the war package. Maybe some people will say stop the server, UNIX is not a stopadmin.sh However, this script performs a normal shutdown weblogic, too slow. I'm here to save my hair time, so stop WebLogic and use a way to kill the Java process directly.

file:autoRefresh.sh

#!/bin/sh
# get PID from process name
#配置相关变量
Plmshome= '/weblogic/bea/user_projects/domains/base_domain/cebplms '
Warfile=cebplms.war
#找到java进程的pid号, and end the process
Pslist= ' ps-u WebLogic |grep java '
For list in $psList
Todo
Pid= $list
Break
Done
echo Stop Pid:pid
Kill-9 $pid
CD $plmsHome
JAR-XVF $warFile

The final summary: In fact, these bat scripts are mainly simulated manual operation, send keyboard commands. Since Telnet is started in DOS, the other batch commands are no longer available because Telnet opens a new shell, so only keyboard commands can be emulated. In particular, do not perform any other actions during the execution. Because the whole process of execution, the equivalent of our own knocking on the keyboard. If you're doing something else, you'll find someone knocking on your keyboard. is exactly the result of the implementation of the VBS file. If you have a better way, I hope to see you.

At the bottom, attach the relevant data of VBS operation keyboard:

The following information is obtained from the Internet, but the source is forgotten.

Automatically log on to a telnet batch file
One. Windows platform:
Copy the code to Notepad and save it as Autotelnet.bat, and then double-click to run to achieve automatic login to Telnet server, the server IP itself modified
@echo off
Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Open 192.168.1.200" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "Engineer{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep->>telnet_tmp.vbs
Echo Sh. SendKeys "ls {ENTER}" >>telnet_tmp.vbs
Start Telnet
cscript//nologo Telnet_tmp.vbs
Del Telnet_tmp.vbs
Appendix:
For SendKeys What this command can send, we can look at the following list:
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
Break {Break}
CAPS LOCK {CapsLock}
Del or delete {delete} or {DEL}
Down ARROW {down}
End {END}
ENTER {enter}or ~
ESC {ESC}
Help {Help}
Home {Home}
INS or insert {Insert} or {INS}
Left ARROW {left}
NUM LOCK {NumLock}
PAGE Down {PGDN}
PAGE up {PgUp}
PRINT Screen {PRTSC}
Right ARROW {right}
SCROLL LOCK {ScrollLock}
tab {TAB}
Up ARROW {up}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}
SHIFT +
CTRL ^
ALT%
Two. Linux Platform

Ensure that your system exists expect this executable program, save the following code to the file autotelnet, and give execution permissions. Detailed Operation View command expect
#!/usr/bin/expect--
Set SERVER "192.168.1"
Set USER "MyUserName"
Set PASSWD "Mypass"
If {$ARGC} {
Spawn telnet $SERVER. $argv
} else {
Spawn Telnet $SERVER. 200
}
Expect "Password:"
Send "$PASSWD/n"
Expect "#"
Send "ls/n"
Interact

By the right, also forgot that the file involves a sleep command, this command window is not, but the online strongman with bat also made this file. are attached together.

@echo off
echo Q | Debug>nul
echo Bj@jzh ' 0x-'/ppppppa (DE (DM) ("Do" ("Dh" (Ls () (LX) (lezrr]eeeuyrx2dx=>sleep.com
Echo 0dxfp,0xx.t0p,=xtgsb4o@$? Piyu Wwx0gwuy wv;ovbx2gv0exgiuht6>>sleep.com
echo t}{z~~ @GwkBG @oekcut ' ~} @MqqBsy sehb~_phxr? @zAB ' lrpeyodt@cj?>>sleep.com
Echo pky_jn@qekpet@ij?jysjn@rekpet@jj?jygjn@sekkjtlgunw?p@pjirz>>sleep.com
Echo Lfvaurq? Oyltq@@?~qcool~rdu@?au?@{qoq?@}ikunwpe~fpeqfwh? Vkk>>sleep.com
echo _gsqocvh{ojeoseiqrma@knefb?p?? Mcjnne~b? M?? Qhetlbgbphexh@e=>>sleep.com
Echo Esogwtlblk?sfu '? Ldod@@k@xo? Suuda?_fkj@n? Kd@? Ua?? O}hcqoq?? R>>sleep.com
Echo _oqol? Cla? Ceu?_fu? Uaq? UBD? LOC? ORO? Uol? UOD? OOI? UGL? Lor@yuo?>>sleep.com
Echo Dsmsqswdor[bqaq? Lua?_l_ounusclooulooduo? Uoe@owh? Uoq? Djtsdm>>sleep.com
Echo Qtqrk@kcmsulkpcloouloofuo?hwdtqostdbntqrrdsdftlnbtm ' lthkct>>sleep.com
echo @dmTkRQSoddTT ~? K? OCOQP?o?? Gds?wow? Pgatachqvnntqv_w? A?it/eh>>sleep.com
echo {zpqpkgk? Jbs? Fqokoh{t?jpvp@iqbdfan? Ohrol? Kj?? Pd~an? Ohrod? G>>sleep.com
echo Q?? Pgt~b?? Oc~?ipo? T?~u?p~cuo0x>>sleep.com
Sleep.com>sleep.exe
Del sleep.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.