• Home
  • Disclaimer
  • Contact
  • Archives
  • About
  • Subscribe
  • Support
  • Advertise

Kernel Talks

Unix, Linux, & Cloud!

  • How-to guides
    • Howto
    • Disk management
    • Configurations
    • Troubleshooting
  • OS
    • HPUX
    • Linux
  • Miscellaneous
    • Software & Tools
    • Cloud Services
    • System services
    • Virtualization
  • Certification Preparations
    • AWS Certified Solutions Architect – Associate
    • AWS Certified Solutions Architect – Professional
    • AWS Certified SysOps Administrator – Associate
    • AWS Certified Cloud Practitioner
    • Certified Kubernetes Administrator
    • Hashicorp Certified Terraform Associate
    • Oracle Cloud Infrastructure Foundations 2020 – Associate
  • Tips & Tricks
  • Linux commands
You are here: Home / Howto

Run command on multiple linux servers from windows

Published: November 3, 2016 | Modified: June 24, 2020



Learn how to run the same/repetitive command on multiple Linux servers from the Windows machine. This trick uses command line putty ‘plink’ utility.

One of the major concerns for sysadmin is to run the same/repetitive command on multiple Linux servers in infra when there is no centralized tool available. In this post, we are going to see how to run a command on multiple Linux servers in one go. There is no need of saving your account password anywhere and even no need to have expect function in your source machine!

Pre-requisite

  • Windows machine with plink downloaded on it (download plink here)
  • Linux servers should be reachable from a windows machine

How to do it

plink is a putty command-line utility. Using plink we will be able to connect to the server by supplying IP, username, password on the command line. plink can be invoked from a command prompt on windows.

C:\Users\noname\Desktop>plink -ssh user1@10.10.1.11 -pw password@123 (hostname; date)
testserver
Tue Nov  1 12:54:33 IST 2016

C:\Users\noname\Desktop>

Goto Windows command prompt by typing cmd in a run window (windows key + r). Navigate to folder where plink executable is kept and then type in plink command as above.

  • ssh: protocol to connect
  • id@server IP
  • pw: account password
  • Commands to execute on Linux server in braces.

This is how plink works. Now to execute the same command on multiple servers we see below example. We will connect to 3 servers and execute hostname & date command.

First, put all 3 server’s IP addresses in single file ip_list.txt. Then execute simple for loop on that file as below in command prompt. This is a very basic batch script.

C:\Users\noname\Desktop>FOR /F "tokens=1,2* delims=," %G IN (C:\Users\noname\Desktop\ip_list.txt) DO plink -ssh user1@%G -pw password@123 (hostname; date)

testserver
Tue Nov  1 12:54:33 IST 2016

testserver1
Tue Nov  1 12:54:36 IST 2016

testserver2
Tue Nov  1 12:54:39 IST 2016

C:\Users\noname\Desktop>

Voila! all server’s command output is there! Commands executed on all servers in one go.

This is very useful when you need to check some single line outputs from all servers or if you want to run account refresh commands on all servers in one go.

⇠ Previous article
Howto get Disk serial number in HPUX
Next article ⇢
Root disk mirroring in itanium HPUX

Related stuff:

  • How to install sar in SUSE Linux
  • How to disable direct root login on Linux & HPUX
  • How to enable repository using subscription-manager in RHEL
  • How to configure proxy for YUM in RHEL, CentOS ?
  • How to configure SFTP with restricted directory access
  • 5 ways to check swap on Linux
  • 4 tools to download any file using the command line in Linux
  • Cowsay: Fun in Linux terminal
  • Format date and time for Linux shell script or variable
  • How to run your script with system boot in HPUX
  • Highest size files in mount point
  • File encryption / password protect file in HPUX

Filed Under: Howto, Tips & Tricks Tagged With: batch command run, command prompt putty, connect multiple linux, how to use plink, linux tricks, scripting, windows to linux

If you like my tutorials and if they helped you in any way, then

  • Consider buying me a cup of coffee via paypal!
  • Subscribe to our newsletter here!
  • Like KernelTalks Facebook page.
  • Follow us on Twitter.
  • Add our RSS feed to your feed reader.

Share Your Comments & Feedback: Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get fresh content from KernelTalks

  • Email
  • Facebook
  • RSS
  • Twitter

Get Linux & Unix stuff right into your mailbox. Subscribe now!

* indicates required

This work is licensed under a CC-BY-NC license · Privacy Policy
© Copyright 2016-2023 KernelTalks · All Rights Reserved.
The content is copyrighted to Shrikant Lavhate & can not be reproduced either online or offline without prior permission.