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.
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]
コメントを追加