diff --git a/README b/README index f5578f21..eaf6c0db 100644 --- a/README +++ b/README @@ -5,10 +5,11 @@ Please send problems and feedback to bug-parallel@gnu.org. = Presentation of GNU Parallel = -GNU Parallel is a shell tool for executing jobs in parallel. A job is -typically a single command or a small script that has to be run for -each of the lines in the input. The typical input is a list of files, -a list of hosts, a list of users, or a list of tables. +GNU Parallel is a shell tool for executing jobs in parallel using one +or more machines. A job is typically a single command or a small +script that has to be run for each of the lines in the input. The +typical input is a list of files, a list of hosts, a list of users, or +a list of tables. If you use xargs today you will find GNU Parallel very easy to use. If you write loops in shell, you will find GNU Parallel may be able to diff --git a/src/parallel b/src/parallel index 1824898d..f751a070 100755 --- a/src/parallel +++ b/src/parallel @@ -10,10 +10,11 @@ B [options] [I [arguments]] [< list_of_arguments] =head1 DESCRIPTION -GNU B is a shell tool for executing jobs in parallel. A job -is typically a single command or a small script that has to be run for -each of the lines in the input. The typical input is a list of files, -a list of hosts, a list of users, a list of URLs, or a list of tables. +GNU B is a shell tool for executing jobs in parallel using +one or more machines. A job is typically a single command or a small +script that has to be run for each of the lines in the input. The +typical input is a list of files, a list of hosts, a list of users, a +list of URLs, or a list of tables. If you use B today you will find GNU B very easy to use as GNU B is written to have the same options as @@ -1140,6 +1141,40 @@ B>B< result> B +=head1 ENVIRONMENT VARIABLES + +The environment variable $PARALLEL will be used as default options for +GNU B. However, because some options take arguments the +options need to be split into groups in which only the last option +takes an argument. Each group of options should be put on a line of its +own. + +=head1 INIT FILE (RC FILE) + +The file ~/.parallelrc will be read if it exists. It should be +formatted like the environment variable $PARALLEL. Lines starting with +'#' will be ignored. + + +=head2 EXAMPLE + +cat list | parallel -j1 -k -v ls + +can be written as: + +cat list | PARALLEL="-kvj1" parallel ls + +cat list | parallel -j1 -k -v -S"myssh user@server" ls + +can be written as: + +cat list | PARALLEL="-kvj1 +-Smyssh user@server" parallel echo + +Notice the newline in the middel is needed because both B<-S> and +B<-j> take an argument and thus both need to be at the end of a group. + + =head1 BUGS Filenames beginning with '-' can cause some commands to give @@ -1320,6 +1355,19 @@ sub parse_options { $Global::default_simultaneous_sshlogins = 9; Getopt::Long::Configure ("bundling","require_order"); + # Add options from .parallelrc + my $parallelrc = $ENV{'HOME'}."/.parallelrc"; + if(-r $parallelrc) { + open (IN, "<", $parallelrc) || die; + while() { + /^\s*\#/ and next; + chomp; + unshift @ARGV, $_; + } + close IN; + } + # Add options from shell variable $PARALLEL + $ENV{'PARALLEL'} and unshift @ARGV, split/\n/, $ENV{'PARALLEL'}; GetOptions("debug|D" => \$::opt_D, "xargs|m" => \$::opt_m, "X" => \$::opt_X, @@ -1518,9 +1566,14 @@ sub generate_command_line { } else { # append args my $arg=join(" ",@quoted_args); - $job_line .= " $arg"; + if($job_line) { + $job_line .= " ".$arg; + } else { + # Parallel behaving like '|sh' + $job_line = $arg; + } } - debug("Return jobline: $job_line\n"); + debug("Return jobline: !$job_line!\n"); } return ($job_line,\@quoted_args); } @@ -2146,7 +2199,7 @@ sub get_next_arg { $arg = shell_quote($arg); } } - debug("Next arg: ".$arg."\n"); + debug("Next arg: !".$arg."!\n"); return $arg; } @@ -2615,7 +2668,7 @@ $Global::control_path = 0; # TODO --max-number-of-jobs print the system limited number of jobs # TODO Debian package -# TODO environment variable and .parallelrc +# TODO transfer a script to be run #=item B<--sshlogin> I<[ncpu/]sshlogin[,[ncpu/]sshlogin[,...]]> (beta testing) # Skilletegn: diff --git a/unittest/actual-results/test21 b/unittest/actual-results/test21 new file mode 100644 index 00000000..ffa47261 --- /dev/null +++ b/unittest/actual-results/test21 @@ -0,0 +1,11 @@ +### Test $PARALLEL +1 +ssh -l parallel parallel-server2 echo\ 1; +1 +ssh parallel-server1 echo\ 2; +2 +### Test ~/.parallelrc +ssh -l parallel parallel-server2 echo\ 1; +1 +ssh parallel-server1 echo\ 2; +2 diff --git a/unittest/tests-to-run/test21.sh b/unittest/tests-to-run/test21.sh new file mode 100644 index 00000000..42a13dca --- /dev/null +++ b/unittest/tests-to-run/test21.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +PAR=parallel +SERVER1=parallel-server1 +SERVER2=parallel-server2 + +echo '### Test $PARALLEL' +echo | PARALLEL=--number-of-cpus $PAR +seq 1 2 | PARALLEL="-S$SERVER1 +-Sssh -l parallel $SERVER2 +-j1" $PAR -kv echo + +echo '### Test ~/.parallelrc' +echo "-S$SERVER1 +-Sssh -l parallel $SERVER2 +-j1" > ~/.parallelrc +seq 1 2 | $PAR -kv echo +rm ~/.parallelrc diff --git a/unittest/wanted-results/test21 b/unittest/wanted-results/test21 new file mode 100644 index 00000000..ffa47261 --- /dev/null +++ b/unittest/wanted-results/test21 @@ -0,0 +1,11 @@ +### Test $PARALLEL +1 +ssh -l parallel parallel-server2 echo\ 1; +1 +ssh parallel-server1 echo\ 2; +2 +### Test ~/.parallelrc +ssh -l parallel parallel-server2 echo\ 1; +1 +ssh parallel-server1 echo\ 2; +2