Batch program: Automatically upload FTP, and then log on to the Linux server to perform updates

Source: Internet
Author: User
Tags goto

----Reprint Please specify the Source: Blog Park-Bang Bang sauce good

Recently in the batch processing program, has not found the ability to work together to use it, a few days ago when testing the service side suddenly thought can do this:

Write a batch program, automatically upload the package via FTP to the specified place, and then automatically log on to the Linux server, unzip the package, for service side updates.

First look at the total dispatch script Auto_update.bat:

Let the user enter the address of the server, and then select the action to be performed.

@echooff&Setlocal enabledelayedexpansion:::::::::::::::::---:::::-:::::----::-::::::::::-::::::::-::::.::::-:::::  ::: :::::::::-----:-::----::::----:--::::::::::::SetUrl=192.168.0.12:: Address of the latest local packageSetSourceaddress=d:\the address of the package stored on the testftp::ftpSettargetaddress=/upload::ftp user name and password to the serverSetFtpname=abcftpSetftppassword=123:: User name and password when telnet on serverSetUserid=abclinux
Setpassword=123456:: The directory where the extracted files are locatedSetuntardir=/tmp/upload::4 Secondary CopySetcopy1=cp/tmp/upload/dst/a.dat/app/-FSetcopy2=cp/tmp/upload/Lis/b.dat/Lis/ -FSetcopy3=cp/tmp/upload/cs/lis/-RFSetcopy4=cp/tmp/upload/test_ci/app/-f:: Directory Name and command required to run the programSetdo1_dir=/lis/Setdo1=./m.shSetdo2_dir=/app/Setdo2=./Test_ciecho Enter the server address for which you want to perform the action:Set/P Url=: Repeatecho.echo.echo ########### #请选择要执行的操作 ########## #echo----1Enter the number 1 and press ENTER to automatically upload the package to the FTP server echo----2. Enter the number 2 and press ENTER to perform the update directly (the user has manually uploaded the package) echo----3. Enter the number 3 and press ENTER to automatically upload the package and update the program echo----4. Enter exit and press ENTER to terminate the script echo Please enter:Set/P choice=:::::::::::::---:-::::---::-:::::-:::-::-:::::-:::::-:::::::.::::: The package is uploaded by the ftp:::::::::::::;:: (:.:) ::::::::::::::::::::::::::if "%choice%"=="1"(Echo Please confirm that you have placed the package in the local directory (Y/N):Set/P yn=if/I"!yn!"=="N" ( Setyn=Goto EndEcho starts uploading the latest local package to the server ...Pagerupload_ftp.bat echo Upload completeGotoRepeat):::-::::::::::--::--::::--::::-:::::-:::::-:::.:::::: Perform the update actions::::::::::::::;::::.::--- :::::::::::::::::::::::::::::::::if "%choice%"=="2"(Echo This operation will be initialized, please confirm that the server has been restarted (Y/N):Set/P yn=if/I"!yn!"=="N" ( Setyn=Goto EndEcho begins to log on to the server for update operation ...PagerRun_the_program.batGotoRepeat):::-::::::::::--::--::::--::::-:::::-:::::-:::.:::::: uploaded and updated by::::.::::::--:-----::::----: ::::::::::::::::::::::::::::::::::if "%choice%"=="3"(Echo This operation will upload and update the program, verify that the package is already in the local specified directory, and has restarted the server (Y/N):Set/P yn=if/I"!yn!"=="N" ( Setyn=Goto EndEcho starts uploading the latest local package to the server ...Pagerupload_ftp.bat echo upload complete echo. Echo starts to log on to the server for update operation ...PagerRun_the_program.batGotorepeat) Echo.echo.if "%choice%"=="Exit"(Echo you entered the%choice% character, the batch automatically exitsGoto End) echo does not recognize the instruction, please re-enterGotoRepeat:EndSetChoice=echo script terminates!

Next is the upload Ftp script upload_ftp.bat:

You cannot run this script individually because the variables that it requires are in the total dispatch script.

@echooff:::.::::::::::--::--::::--::::--::::--::::,:::::-- :. Upload processes::::::::::::::--:--:----- :::::::::::::::::::::::::::REMLogin FTPecho Open%url% >autoftp.ftpREMEnter user name and password to loginecho User%ftpname%%ftppassword%>>Autoftp.ftpecho binary>>autoftp.ftpREMswitch to a directory in FTPecho CD%targetaddress% >>autoftp.ftpREMswitch to a local directoryecho LCD%sourceaddress% >>autoftp.ftpREMset to: No user is required to confirm each fileEcho Promptoff>>autoftp.ftpREMStart uploadingEcho Mput * >>Autoftp.ftpecho Bye>>Autoftp.ftpecho quit>>AUTOFTP.FTP::::.::::::::::::::-----:-::::--:::::::-::::::::::::::::.::::::::-:::::.::: Perform an upload:::::::::::::.:.:::-:--::: ::: :::::::::::--:::------------.-N-S:autoftp.ftpdel autoftp.ftp

Finally, the server-side update script Run_the_program.bat:

You cannot run this script individually because the variables that it requires are in the total dispatch script.

@echooffEchoSetSh=wscript.createobject ("Wscript.Shell") >Telnet_tmp.vbs::::.::::::::::-:::::::::::-::-:::::::::::::::::::::::::::::::::.::::::.:::: Login:::::::::::::::  ::: ::::::::,::------------:----Wscript.Sleep +>>Telnet_tmp.vbsecho Sh. SendKeys"%userid%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep +>>Telnet_tmp.vbsecho Sh. SendKeys"%password%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep ->>Telnet_tmp.vbs::::.::::::::::-:::::::-::::::::::::::::::::::-:::::-::::::::::::::.:::: Decompression::::::::::::::-::  ::-:::::::::------:::::-------------------------::::-::- SendKeys"CD%untardir%{enter}">>Telnet_tmp.vbsecho Sh. SendKeys"TAR-ZXVF H{tab}">>Telnet_tmp.vbsecho Sh. SendKeys"{ENTER}">>Telnet_tmp.vbsecho Wscript.Sleep ->>Telnet_tmp.vbs::::.:::::::::::::-------:::-----:--::::::::::-::::::-:::::.:::::;:: : Copy files to the specified directory::.:::::::::::::: :::--::::::::--::::--------------- SendKeys"%copy1%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep the>>Telnet_tmp.vbsecho Sh. SendKeys"%copy1%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep10000>>Telnet_tmp.vbsecho Sh. SendKeys"%copy1%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep10000>>Telnet_tmp.vbsecho Sh. SendKeys"%copy1%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep10000>>Telnet_tmp.vbs::::.::::::::::::::-----:-::::--:::::::-::::::::::::::::.::::::::-:::::.::: Run a program::.:::::::::::::: :::::::::::::::::::::::-------:::---------: SendKeys"CD%do1_dir%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep +>>Telnet_tmp.vbsecho Sh. SendKeys"%do1%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep15000>>Telnet_tmp.vbsecho Jump Directory, start the official run program ... echo Sh. SendKeys"CD%do2_dir%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep +>>Telnet_tmp.vbsecho Sh. SendKeys"%do2%{enter}">>Telnet_tmp.vbsecho Wscript.Sleep10000>>Telnet_tmp.vbs::::.::::::::::-:::::::-::::::::::::::::::::::-:::::-::::::::::::::.:::: To begin with:::::::::::::::-----. :::::::::::::: "::::":::: "%url%"::::::: ":": ":" Start Telnet%url%cscript telnet_tmp.vbsdel telnet_tmp.vbs

The program has passed, but I modified some server information (company information to keep it ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

When running, you only need to use the Cmd.exe window under Windows, switch to the directory where the above three programs are located, enter auto_update.bat press ENTER.

Batch program: Automatically upload FTP, and then log on to the Linux server to perform updates

Related Article

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.