Is there a better way to do this? BASH

Matthew
ssh -p 10551 -S /tmp/manpagemaker/ssh.connect -MfN [email protected]

for xe in ${XECOMMANDS[@]} ;do

    xe=$(echo ${xe#*-}) ; xe=$(echo ${xe%.*})
    ssh -p 10551 -S /tmp/manpagemaker/ssh.connect [email protected] t 'bash -s' < ./manpagemaker.sh "$xe"

done

Is there a better way to do this? I feel like my method is very inefficient.

I have wrote a script that builds a asciidoc template for a manpage. I'm writing manpages for the xe command that is part of the xapi. The "manpagemaker.sh" script depends on the xe command to execute properly, which is present on my remote xenserver cloud.

So instead of opening a new ssh connection for every instance of manpagemaker I need to run, could I some how use a named pipe and stream it do my xenserver cloud? Keep in my mind I need to add a redirect eventually to capture all the text sent to stdout.

Aleks-Daniel Jakimenko-A.

You can try piping a function to xargs:

showCommands() {
    for xe in ${XECOMMANDS[@]}; do
        xe=$(echo ${xe#*-}) ; xe=$(echo ${xe%.*})
        echo "$xe"
    done
}

showCommands | xargs -l1 ssh -p 10551 -S /tmp/manpagemaker/ssh.connect [email protected] t 'bash -s' < ./manpagemaker.sh

I don't know the contents of XECOMMANDS, but is seems like that this code is broken with cases when filenames contain space characters. Here is a way to fix that:

showCommands() {
    for xe in "${XECOMMANDS[@]}";do
        echo -n "$xe"
        echo -ne '\0'
    done
}

showCommands | xargs -0 -l1 ssh -p 10551 -S /tmp/manpagemaker/ssh.connect [email protected] t 'bash -s' < ./manpagemaker.sh

-l1 means that xargs will read the pipe input line by line.

Since filenames can't contain a null character I used \0 to split parameters.

If you want to pass more than one parameter to ssh, then you have to increase -l by one and add another echo output. Here's an example:

showCommands() {
    for xe in "${XECOMMANDS[@]}";do
        echo -n "$xe"
        echo -ne '\0'
        echo -n 'This is another parameter'
        echo -ne '\0'
    done
}

showCommands | xargs -0 -l2 ssh -p 10551 -S /tmp/manpagemaker/ssh.connect [email protected] t 'bash -s' < ./manpagemaker.sh

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

better way to do this in MATLAB?

分類Dev

Is there a better way to do Insertion Sort?

分類Dev

Is there a better way to do this than echo?

分類Dev

Do you know a better way to write this method?

分類Dev

Is there a better way to do this code? Perhaps using filter or reduce?

分類Dev

Is there a better way of comparing dates

分類Dev

A better way to detect the cursor?

分類Dev

Better way to return boolean

分類Dev

A better way to introspect a capture

分類Dev

Is there a better way to loop code?

分類Dev

Is there a better way to do modulo in a finite field when directly working on polynomials rather than binary numbers?

分類Dev

Is there a better way to define a global variable?

分類Dev

Decorator with Arguments: Would this be a better way?

分類Dev

Is this possible using LEAD or is there a better way?

分類Dev

Is there a way of making discord embeds better?

分類Dev

Better way to override a function definition

分類Dev

Is there a better way to divide this string into substrings?

分類Dev

In bash, is it generally better to use process substitution or pipelines

分類Dev

Are these two bash snippets equivalent and if not which is better?

分類Dev

Is there a better way to re-use plots Matplotlib?

分類Dev

Better way of capturing multiple same tags?

分類Dev

Better way to execute nested for loops to generate a dict?

分類Dev

Better way of error handling in Kafka Consumer

分類Dev

rxJava better way to wait on a specific sequence of values

分類Dev

Which way of setting fields value is better and why?

分類Dev

Which way of setting fields value is better and why?

分類Dev

AngularJS: Is there a better way to achieve this than the one specified?

分類Dev

Better way to write jquery add/remove class

分類Dev

better way to load 2 dropdown in mvc

Related 関連記事

  1. 1

    better way to do this in MATLAB?

  2. 2

    Is there a better way to do Insertion Sort?

  3. 3

    Is there a better way to do this than echo?

  4. 4

    Do you know a better way to write this method?

  5. 5

    Is there a better way to do this code? Perhaps using filter or reduce?

  6. 6

    Is there a better way of comparing dates

  7. 7

    A better way to detect the cursor?

  8. 8

    Better way to return boolean

  9. 9

    A better way to introspect a capture

  10. 10

    Is there a better way to loop code?

  11. 11

    Is there a better way to do modulo in a finite field when directly working on polynomials rather than binary numbers?

  12. 12

    Is there a better way to define a global variable?

  13. 13

    Decorator with Arguments: Would this be a better way?

  14. 14

    Is this possible using LEAD or is there a better way?

  15. 15

    Is there a way of making discord embeds better?

  16. 16

    Better way to override a function definition

  17. 17

    Is there a better way to divide this string into substrings?

  18. 18

    In bash, is it generally better to use process substitution or pipelines

  19. 19

    Are these two bash snippets equivalent and if not which is better?

  20. 20

    Is there a better way to re-use plots Matplotlib?

  21. 21

    Better way of capturing multiple same tags?

  22. 22

    Better way to execute nested for loops to generate a dict?

  23. 23

    Better way of error handling in Kafka Consumer

  24. 24

    rxJava better way to wait on a specific sequence of values

  25. 25

    Which way of setting fields value is better and why?

  26. 26

    Which way of setting fields value is better and why?

  27. 27

    AngularJS: Is there a better way to achieve this than the one specified?

  28. 28

    Better way to write jquery add/remove class

  29. 29

    better way to load 2 dropdown in mvc

ホットタグ

アーカイブ