parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamically changing remote servers list


From: Ole Tange
Subject: Re: Dynamically changing remote servers list
Date: Sat, 30 Aug 2014 08:19:48 +0200

On Sat, Aug 30, 2014 at 5:25 AM, Douglas A. Augusto <daaugusto@gmail.com> wrote:
> On 28/08/2014 at 00:38,
> Ole Tange <ole@tange.dk> wrote:
>
>> You should test that it works with all the supported styles of
>> sshlogins. From the man page:
>
> Hi,
>
> I made the script more robust and it now seems to support all the styles of
> sshlogins:
>
> ################################################################################
>    cp original.slf updated.slf
>    while [ 1 ] ; do
>       nice parallel --timeout 1000% --nonall -j0 -k --slf original.slf --tag 
> echo | \
>          sed -e 's#\t$##' -e '#\t#d' | \
>          nice parallel -k "sed -n 's#^\([[:digit:]]\+/\)\{0,1\}{}\$#&#p' 
> original.slf | head -n 1" > tmp.slf
>       if ! cmp -s tmp.slf updated.slf; then
>          mv tmp.slf updated.slf
>       fi
>
>       sleep 10
>    done &
>
>    parallel --slf updated.slf ...
> ################################################################################
>
> The command which, given a sshlogin string, recovers the full entry from the
> original slf file (original.slf) is:
:

Seems sound.

> There are two minor limitations, though:
>
>    1) If the original.slf contains duplicate entries differing only by the
> specification of the number of slots, such as:
>
>    server.net
>    8/server.net
>
> only the first one will be picked (this is what 'head -n 1' does).

If you are putting duplicate entries in .slf, you are asking for
trouble, so that is fine.

>    2) I'd like to prevent the replacement {} from being quoted by GNU 
> Parallel,
> but it insists on converting something like:
>
>    ssh -p 2222 server.domain.net
>
> into
>
>    ssh\ -p\ 2222\ server.domain.net
>
> This by itself doesn't seem to be a problem within sed. The problem is that I
> cannot quote the dots in server.domain.net (making it server\.domain\.net,
> turning off their special meaning within sed) because GNU Parallel overrides
> any attempt of doing so. For instance, the following would work:
>
>    parallel --rpl '{quote} s#\.#\\.#g' -k "sed -n 
> 's#^\([[:digit:]]\+/\)\{0,1\}{quote}\$#&#p' original.slf | head -n 1"
>
> but only if replace this line:
>
>    my $cmdstring = 
> $self->replace_placeholders($self->{'command'},$Global::quoting,$quote_arg);
>
> by
>
>    my $cmdstring = 
> $self->replace_placeholders($self->{'command'},$Global::quoting,0);
>
> in GNU Parallel's source code. Am I missing something?

GNU Parallel always assumes the {} will be parsed by shell. So never do:

   "foo 'pre{}post'"

but always do:

   "foo 'pre'{}'post'"

In most situations they do the same, but you are hitting one of the
few situations where they do not.

To turn off the special meaning of . you can use \Q..\E in perl:

   . is any char here\QHere . means [\.] and not any char\E. is any char again

So replace the sed with perl and do something like:

   '^(\d+/)?\Q'{}'\E$'

/Ole



reply via email to

[Prev in Thread] Current Thread [Next in Thread]