Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 919345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:31:43+00:00 2026-05-15T18:31:43+00:00

I have a quick script to run a command on each server using ssh

  • 0

I have a quick script to run a command on each server using ssh (i am sure there are lots of better ways to do this, but it was intended to just work quick!!). For the test1 etc, there is no server so the script continues, the script also continues if the pubkey auth fails. However if the script connects, the date is printed but the ssh loop terminates…

#!/bin/bash -x

cat <<EOF |
##file servers
test1
test2
server1
server2
EOF
while read line
do
if [ "${line:0:1}" != "#"  ]; then

ssh -q -oPasswordAuthentication=no -i id_dsa user1@${line} date

fi
done

echo read line must have exited

output is like so;

+ cat
+ read line
+ '[' t '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa user1@test1 date
+ read line
+ '[' t '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa user1@test2 date
+ read line1
+ '[' s '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa user1@server1 date
Fri Jul  9 09:04:16 PDT 2010
+ read line
+ echo read line must have exited
read line must have exited`enter code here`

something to do with the successful return of the ssh command is messing with the condition for the loop or the var… any suggestions on why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:31:44+00:00Added an answer on May 15, 2026 at 6:31 pm

    You should pass the -n flag to ssh, to prevent it messing with stdin:

    ssh -n -q -oPasswordAuthentication=no -i id_dsa user1@${line} date
    

    I tested this with my own server and reproduced the problem, adding -n solves it. As the ssh man page says:

    Redirects stdin from /dev/null
    (actually, prevents reading from
    stdin)

    In your example, ssh must have read from stdin, which messes up your read in the loop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Have you marked your web service class with ScriptService attribute?… May 16, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer You still have to add "south" to your INSTALLED_APPS list… May 16, 2026 at 1:55 pm
  • Editorial Team
    Editorial Team added an answer Are you trying automate one script with another? If that's… May 16, 2026 at 1:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there a simple way to run a Python script on Windows/Linux/OS X? On
A quick question. I have a simple table with this structure: USERS_TABLE = {id},
Say I have a string like this: $string = 'The /*quick*/ brown /*fox*/ jumped
I have a quick question. I'm matching class names of LI elements to turn
I am starting out with PRADO php framework and i have a quick question:
I have a question regarding quick initialization of swing components. At the start of
UPDATE: this is a repost of How to make shell scripts robust to source
I have a text file that contains a list of filenames, minus the extension,
I am following the hints to this question , but I'm impatient and I
I have a class I use to split a string of SQL commands by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.