How do I automatically connect to a Linux/mac machine to run shell scripts from the Windows platform?

Source: Internet
Author: User
Tags echo command

Not a new knowledge, but for a small white like me, if you can find an early morning to summarize the experience from the actual combat, will not be busy today only drink two glasses of water (well, bold but cautious thick skin is my life motto ╭ (╯^╰) ╮)

Background:

A project requires impersonating a concurrent user from the Performance test tool LoadRunner to invoke a shell script located on a single Mac virtual machine.

Putty Batch Shutdown http://alwaysyunwei.blog.51cto.com/3224143/1223455/

Method One: Plink Windows Bat (Common method)

The principle of this approach is to telnet to the server and run the shell script automatically with the Plink tool putty with the free OpenSSH tool on Windows.

Step 1: Download the Plink.exe & putty.exe value Local directory, such as D:\Proram Files\plink.exe. Both of these software are free-to-install versions.

Step 2: Place the shell script you want to run into your local directory. such as c:\test.sh

Step 3: Create a Tet.bat file and write the following command in it:


= This method I test not pass, using putty implementation of


@echo off

D:

CD Program Files

plink-l [userName]-pw [password]-M c:\test.sh [ServerName or IP]

Exit

Once saved, double-click to run. It is important to note that my plink.exe is placed in the Program Files folder on D, which corresponds to the second and third lines of the script above. The actual usage needs to be replaced with the currently placed Plink.exe directory. It's also important to note that the shell script you want to run is going to be put on your local, I thought it was put on the server side, and see some of the online posts are also written on the server side, it turns out that the operation is not enough, so here also need to pay attention.

At run time, the command line window pops up for a while and then closes automatically. If you want to check whether the test.sh is really running, it is recommended to add some debug output statements in the test.sh, output the content to a file, and then you can access the server through putty or other SSH client and view the output file.

It is also necessary to note that in the Mac machine's system preference/sharing configuration, the remote logon needs to be checked, or the SSH connection will fail to build. (This I tangled, and finally Frank found the solution~)

As for calling test.bat This batch file in LoadRunner, it is easier to use the system () function. Perl or shell scripts are called similarly.

Putty Method:

Download Putty.exe (Green edition)

Bat as follows


@echo off

@color 0A

Set path=%cd%

CD%path%

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" Tom[email protected]

Pause




= = included Restart script


@echo off

@color 0A

Set path=%cd%

CD%path%


: input

@echo 0.101━━━━ Sichuan Chongqing API Server ━━━━

@echo 0.103━━━━ Sichuan Chongqing DAO Server ━━━━

@echo 0.130━━━━ Data platform, four-member linkage server ━━━━

@echo 0.131━━━━SAAS-API Server ━━━━

@echo 0.132━━━━saas-dao Server ━━━━

@echo 0.180━━━━ Fast Consumer goods server ━━━━

set/p floor= ... Please enter the server for the application that needs to be restarted (e.g. 0.101, 0.103, please enter 101, 103):


If%floor% NEQ 101 (

If%floor% NEQ 103 (

If%floor% NEQ 130 (

If%floor% NEQ 131 (

If%floor% NEQ 132 (

If%floor% NEQ 180 (

If%floor% NEQ 5 (

If%floor% NEQ 9 (

If%floor% NEQ 10 (

If%floor% neq 11 (

If%floor% NEQ 12 (

If%floor% NEQ 13 (

If%floor% NEQ 14 (

If%floor% NEQ 15 (

If%floor% NEQ 16 (

Echo.

echo Please check if the server you entered exists

Goto:input

)

)

)

)

)

)

)

)

)

)

)

)

)

)

)


If%floor%== 101 (

@echo Select 101, restarting Sichuan Chongqing API application

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo Restart Sichuan Chongqing API application end .... 0.130

Goto:end 0.130

) 0.130

If%floor%== 103 ( 0.130

@echo Select 103, restarting Sichuan Chongqing DAO application 0.130

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo restart Sichuan Chongqing DAO application end .... 0.130

Goto:end 0.130

) 0.130

If%floor%== ( 0.130

@echo Select 130, restart data platform four member linkage application 0.130

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo Restart Data platform four-member linkage application end .... 0.130

Goto:end 0.130

) 0.130

If%floor%== 131 ( 0.130

@echo Select 131, restarting the SAAS-API application 0.130

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo Restart Saas-api app end ..... 0.130

Goto:end 0.130

) 0.130

If%floor%== ( 0.130

@echo Select 132, restarting the Saas-dao application 0.130

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo Restart Saas-dao app end ..... 0.130

Goto:end 0.130

) 0.130

If%floor%== ( 0.130

@echo Select 180, you are restarting the FMCG application 0.130

"%path%/putty.exe"-SSH-PW thwltomcat-m "%path%/restart.txt" [email protected]

@echo Restart FMCG application end .....

Goto:end

)


)

: End

@echo Restart the Tomcat service end ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━


Pause






Method Two: The RTE protocol recording with LR

The principle of this method is to use LoadRunner's own RTE (Remote Terminal Emulation) protocol to directly record the user to establish SSH connection and activity process and into the LR script. The steps are as follows:

Step 1: Modify the recording options. (The following is for recording Linux server only)

1) Cancel all IBM-related tick

2) Select Session type=telnet, Port =22,terminal type=ssh, then click the Connect button to record.

Step 2: Modify and debug the script.

Step 3: Run the script in the controller.

The first two steps are fine, but step 3 encounters a variety of obstacles. First of all, IP spoofing cannot be enabled, otherwise the protocol you choose does not support the prompt to run on a thread, and after the IP spoofing is removed, it is found that the generator CPU resources are quickly filled up by the mdrv.exe process and die directly in the 100%. Even if you run a single user, Mdrv.exe will account for about 50% of the CPU. I saw some peers on the internet with the RTE protocol on a single machine simulated over 300 users, do not know why I recorded the ssh login echo command execution exit will be so resource. In the group asked also no one knows, perhaps this agreement in the company not so much, it is said that the banking sector will be used. The last problem is that the user runs through the first iteration and waits there, no longer running the next iteration, or exiting the system. Vugen Multi-iteration is completely barrier-free Ah, also checked the controller in pacing what is not a problem, scratching the head did not think of why, crazy Ah!

This is the outcome of today's work, and finally the solution. Scenario two follow-up can continue to study, it seems that it projects need to use the protocol outside of HTTP and Cisco bought the opportunity of license is really very rare ah ...


This article from the "Faint Tears" blog, reproduced please contact the author!

How do I automatically connect to a Linux/mac machine to run shell scripts from the Windows platform?

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.