Linux Stall
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials
No Result
View All Result
Linux Stall
No Result
View All Result
Home How to

Running Commands Automatically Over SSH

Chankey Pathak by Chankey Pathak
July 12, 2020
in How to
43 2
0
Blue padlock icon computer security system Encryption
15
SHARES
752
VIEWS
Share on FacebookShare on Twitter

In this quick and simple post I will be showing you an easy way to automatically run commands over SSH. This method works great with bash loops if you need to run the same commands over multiple servers. Using this method automatically disconnects once the command or commands are finished executing, you will receive the full output however.

Automatically Run Commands Once Connected

To accomplish this you simply enter the commands after the domain or IP you intend to ssh to. Here is an example of running the uptime command below:

ssh [email protected] "uptime"

If you would like to run more than one command then you can also do this by using a semicolon between commands.

ssh [email protected] "hostname; uptime; uname -r"

Automatically Run Commands On Multiple Servers

You can accomplish this by either using parellels (will write a post on this at a later date) or by using a for loop. You do not need to save this as a script if you are using bash, simply run the loop directly in your terminal. You can switch to bash if you are using another shell by running /bin/bash.

If you are doing this on multiple servers I recommend running the hostname command first as it makes it easier to see which server gave which response. Here are two examples of using a for loop to accomplish this.

for a in 'server1' 'server2' 'server3'; do
ssh [email protected]$a "hostname; commands";
done;
for a in '[email protected]' '[email protected]' '[email protected]'; do
ssh $a "hostname; commands";
done;
Tags: automationhow tossh
Previous Post

Brocade: Health Check Commands

Next Post

How To Enable TLS Encryption On Postfix

Chankey Pathak

Chankey Pathak

Data Scientist at Morgan Stanley. I've been using Linux since past 12 years. I plan to share what I know about Linux in this blog.

Related Posts

The three-dimensional network topology infographics with ip addresses 3d illustration
How to

Identifying and Resolving IP Address Conflicts with Linux

July 23, 2020
procmon
How to

Microsoft releases ProcMon (Process Monitor) utility for Linux

July 21, 2020
searching file
How to

How to find files by size in Linux

July 12, 2020
Blue padlock icon computer security system vector
How to

How To Enable TLS Encryption On Postfix

July 12, 2020
sar command output
How to

How to Install And Enable SAR (SYSSTAT) On Linux Servers

July 12, 2020
postfix-mailserver logo
How to

Remove OS Information From Postfix Banner

July 12, 2020
Next Post
Blue padlock icon computer security system vector

How To Enable TLS Encryption On Postfix

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Terms and Conditions
  • Contact Us
  • About Us

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

No Result
View All Result
  • Home
  • Android
  • How to
  • Perl
  • Tips
  • Tutorials

© 2012 - 2020 Linux Stall - A place for all your Linux needs.

Welcome Back!

Login to your account below

Forgotten Password?

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In