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

  • Home
  • SEARCH
  • 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 6098621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:10:45+00:00 2026-05-23T13:10:45+00:00

I currently have the following lines of code in a script: set -A ARRAY

  • 0

I currently have the following lines of code in a script:

set -A ARRAY OPTION1 OPTION2 OPTION3 OPTION4
          set -A matches

          for  OPTION in  ${ARRAY[@]}; do
                  DIFF=$(ssh $USER@$host  " diff $PERSONALCONF $PRESETS$OPTION" )
                  if [[ $DIFF == "" ]]; then
                          set -A matches"${matches[@]}" $OPTION
                  fi
          done

Basically, I have a loop that goes through each element in a pre-defined array, connects to a remote server (same server each time), and then compares a file with a file as defined by the loop using the diff command. Basically, it compares a personal.conf file with personal.conf.option1, personal.conf.option2, etc. If there is no difference, it adds it to the array. If there is a difference, nothing happens.

I was wondering if its possible to execute this or get the same result (storing the matching files in an array ON THE HOST MACHINE, not the server that’s being connected to) by way of only connecting once via SSH. I cannot store anything on the remote server, nor can I execute a remote script on that server. I can only issue commands via ssh (kind of a goofy setup). Currently, it connects as many times as there are options. This seems inefficient. If anyone has a better solution I’d love to hear it.

  • 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-23T13:10:46+00:00Added an answer on May 23, 2026 at 1:10 pm

    Several options:

    • You can use OpenSSH multiplexing feature (see ssh(1)).

    • Also, most shells will gladly accept a script to run over stdin, so you could just run something like

      cat script.sh | ssh $HOST /bin/sh
      
    • Most scripting languages (Perl, Python, Ruby, etc.) have some SSH module that allows connection reuse:

      #!/usr/bin/perl
      use Net::OpenSSH;
      my ($user, $host) = (...);
      my @options = (...);
      my @matches;
      my $ssh = Net::OpenSSH->new("$user\@$host");  
      for my $option (@options) {
          my $diff = $ssh->capture("diff $personal_conf $presets$option");
          if ($ssh->error) {
              warn "command failed: " . $ssh->error;
          }
          else {
              push @matches, $option if $diff eq '';
          }
      }
      print "@matches\n";
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently I have the following code: String select = qry.substring(select .length(),qry2.indexOf( from )); String[]
currently i have jdbc code with the following basic stucture: get Connection (do the
I have a select query that currently produces the following results: Description Code Price
I'm currently using this jQuery Cycle Plugin: http://jquery.malsup.com/cycle/ And I have the following code:
I have the following code that correctly generates the CKEditor: <script> $(function(){ $(#newWrite_body).ckeditor({ extraPlugins
I currently have a CSS <ul><li> dropdown menu that uses the following code. Unfortunately
I currently have the following line of code elseif($_POST['aspam'] != 'fire'){ print Is ice
I have the following problem using subversion: I'm currently working on the trunk of
I currently have speakers set up both in my office and in my living
I have the following bit of code. I'm trying to dynamically add drop-down options

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.