Operate Telnet in DOS batch for Automatic Remote Login

Source: Internet
Author: User

Shortly after joining the work, the Project Manager handed over the task of program release to me. There was a new feeling in the first few days. After a long time, there were just a few commands that really didn't mean much, but I still have to do it. I am a lazy man. I tried n long times and finally got a lazy tool. Write it out and share it with you!

Bytes ------------------------------------------------------------------------------------------------------

My work environment Configuration:

Development Tool: ecplise

Database: Oracle10g

Test server: HP-UX + weblogic9.2

Since it was developed by dozens of people at the same time, we first updated our code to the CVS server, compress it into a war package, transmit it to the test machine using FTP, decompress the package, and restart weblogic. Deploy the package to the test machine (the war package must be decompressed under the test machine ).

Bytes -------------------------------------------------------------------------------------------------------

Let's take a look at my total job scheduling script.

File: autorefresh8.bat

@ Echo off
:::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::
:::::::::::::::::::: Set the configuration of the 10.1.18.8 server ::::::::::::::
:::::::::::::::::::::::::::::::::::::::: ::::::::::::::::::::
: Server address
Set url = 10.1.18.8
: User name and password for remote Logon
Set userid = weblogic
Set Password = weblogic
: Logon home directory
Set homedir =/WebLogic
: Directory and file name for executing shell scripts
Set shdir =/WebLogic/syang
: Decompress and stop the shell script file name of the server.
Set stopshfilename = stopandextract. Sh
: Name of the shell script file that starts the server
Set startshfilename = startadmin. Sh
: Extract wait time
Set times = 25000
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
:::::::::::::::::::::: Stop the server and decompress the latest war package :::::::::::: ::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
Echo stop the server and decompress the deployment file...
Call stopandextract. bat
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
:::::::::::::::::::::: Upload the latest jar package and related configuration files ::::::::::::: ::::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
Echo uploads the jar package and configuration file from the local machine to 10.1.18.8...
Call ftp_8.bat
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
:::::::::: :::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
Echo starts the server...
Call startadmin. bat

 

Telnet to the server and decompress the war package

File: stopandextract. bat

@ Echo off
Echo set SH = wscript. Createobject ("wscript. Shell")> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::
::::::::::::::::::: :::
:::::::::::::::::::::::::::::::::::::::: ::::::
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "% userid % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "% password % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
:::::::::::::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Echo Sh. sendkeys "cd % homedir % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
::::::::::::::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Echo Sh. sendkeys "cd % shdir % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
:::::::::::::::::::: ::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Rem echo stops Weblogic and decompress the war package
Echo Sh. sendkeys "sh % stopshfilename % {enter}"> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Echo wscript. Sleep % times %> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Echo Sh. sendkeys "exit {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "Quit {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "{enter}"> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: ::::::::
::::::::::::::::::::: ::
:::::::::::::::::::::::::::::::::::::::: ::::::::
Start Telnet % URL %
: Cscript telnet_tmp.vbs
: Del telnet_tmp.vbs

 

Because there are two test servers, and the two servers need a special jar package, and the internal content is not exactly the same, so they can only be uploaded separately

File: ftp_8.bat

@ Echo off
FTP-ns: ftp_10.1.18.8.ftp

 

Automatic FTP script

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 300> telnet_tmp.vbs
Echo Sh. sendkeys "% userid % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "% password % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
:::::::::::::::::::::::: Go to the home directory and start the service ::::::::::: :::::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
Echo Sh. sendkeys "cd % homedir % {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "sh % startshfilename % {enter}"> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
::::::::: :::::::::::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "exit {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "Quit {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "{enter}"> telnet_tmp.vbs
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
::::::::: :::::::::::::::::
:::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::
Start Telnet % URL %
Cscript telnet_tmp.vbs
: Del telnet_tmp.vbs

 

 

The shell script for stopping the WebLogic Server and extracting the war package is attached. Some people may say that the server is stopped. There is not stopadmin. Sh in Unix. However, the script is executed normally to close WebLogic, which is too slow. In order to save sending time, WebLogic stops using the method of killing Java processes directly.

File: autorefresh. Sh

#! /Bin/sh
# Get PID from process name
# Configure related variables
Plmshome = '/WebLogic/BEA/user_projects/domains/base_domain/cebplms'
Warfile = cebplms. War
# Locate the Java Process PID and end the process
Pslist = 'ps-u WebLogic | grep Java'
For list in $ pslist
Do
PID = $ list
Break
Done
Echo stop PID: PID
Kill-9 $ PID
CD $ plmshome
Jar-xvf $ warfile

 

 

Conclusion: In fact, these bat scripts are used to simulate manual operations and send keyboard commands. Because telnet is enabled in DOS, other batch processing commands are no longer available, Because telnet has opened a new shell, so you can only simulate keyboard commands. Do not perform other operations during execution. Because the entire execution process is equivalent to typing on the keyboard. If you are doing other things, you will find someone playing on your keyboard. This is exactly the result of the execution of the vbs file. If you have a better method, I hope you will be enlightened.

 

At the end of the page, attach the vbs operation keyboard information:

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

Automatic logon to telnet batch files
I. Windows:
Copy the code to notepad and save it as autotelnet. bat. Then, double-click it to automatically log on to the Telnet server and modify the Server IP address.
@ Echo off
Echo set SH = wscript. Createobject ("wscript. Shell")> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "Open 192.168.1.200"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "{enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "engineer {enter}"> telnet_tmp.vbs
Echo wscript. Sleep 300> telnet_tmp.vbs
Echo Sh. sendkeys "ls {enter}"> telnet_tmp.vbs
Start Telnet
Cscript // nologo telnet_tmp.vbs
Del telnet_tmp.vbs
Appendix:
For what the sendkeys 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 %
II. Linux platform

Make sure that your system has an executable program, save the following code to the file autotelnet, and grant the execution permission. Detailed operation view command audit CT
#! /Usr/bin/CT --
Set server "192.168.1"
Set User "myusername"
Set passwd "mypass"
If {$ argc }{
Spawn Telnet $ server. $ argv
} Else {
Spawn Telnet $ server.200
}
Reset CT "Password :"
Send "$ passwd/N"
CT "#"
Send "ls/N"
Interact

 

By the way, I forget that the file involves a sleep command. This command does not exist in the window, but the attackers on the Internet also use bat to make this file. Attached together.

 

@ Echo off
Echo q | debug> NUL
Echo bj @ jzh '0x-'/ppppppa (De (DM (do (DH (LS (LU (LX (lezrr] eeeuyrx2dx => sleep.com
Echo 0 dxfp, 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 ~ Fpestmwh? 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 _ oqos? ? 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.