DEV Community

Alistair Mckeown
Alistair Mckeown

Posted on

Bash script for testing logging on

HI,
I haven't done Bash scripting in a while. Got a simple problem. I want to test the logging on via ssh to 100+ servers from a single jumpbox.

!/bin/bash

for host in $(cat servers.txt)
do ssh -q -o NumberOfPasswordPrompts=1 "$host" "hostname"
done > test.log

This is my attempt its pretty simple and works as long as you're pressing the return key all the time!

Is there anything better out there?

Top comments (1)

Collapse
 
rpalo profile image
Ryan Palo

Hi there! Welcome to the community! I found this answer to a similar question on StackOverflow. I tested it out and it seems to work well as long as you use an ssh key that doesn't have a passphrase on it.

On a DEV tips note:

  1. You can use triple backticks with a programming language to get syntax highlighting:

Using syntax highlighting markdown features.

This yields:

#!/bin/bash

for host in $( cat servers.txt ); do
    ssh # ...
done > test.log
Enter fullscreen mode Exit fullscreen mode
  1. You can use the help tag on your articles to have it featured in section of the site specifically for asking questions and getting help.

#help

A place to ask questions and provide answers. We're here to work things out together.

Let me know if this helps!