aboutsummaryrefslogtreecommitdiff
path: root/rex.man8
blob: 37eb1cd1eaa1f93738b9472e10f0a957e7a19686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
.\" This file is part of rex - a remote execution utility  -*- nroff -*-
.\" Copyright (C) 2012-2022 Sergey Poznyakoff
.\"
.\" Rex is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 3, or (at your option)
.\" any later version.
.\"
.\" Rex is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with Rex.  If not, see <http://www.gnu.org/licenses/>.
.TH REX 8 "March 17, 2022" "REX" "Rex User Reference"
.ds ET /etc
.SH NAME
rex \- remote execution utility
.SH SYNOPSIS
\fBrex\fR\
 [\fB\-NVdlnvh\fR]\
 [\fB\-c\fR \fIFILE\fR]\
 [\fB\-\-config=\fIFILE\fR]\
 [\fB\-\-noop\fR]\
 [\fB\-\-no\-init\-file\fR]\
 [\fB\-\-no\-rc\-file\fR]\
 [\fB\-\-no\-resolve\fR]\
 [\fB\-\-verbose\fR]\
 [\fB\-\-version\fR]\
 [\fB\-\-help\fR]\
 \fICOMMAND\fR\
 [\fIARG\fR...]
.SH DESCRIPTION
.B Rex
runs a supplied command or shell script on several hosts in
succession or in parallel.  It can also be used to copy a file or
files to several hosts. 
.PP
The two main \fICOMMAND\fRs are \fBrun\fR, which runs the specified
command on multiple hosts, and \fBcopy\fR, or \fBcp\fR, which copies
files to them.
.PP
For both commands, there are two ways to select hosts to operate upon.
.PP
The first way is the \fB\-H\fR (\fB\-\-host\fR) option.  Its argument
is either a single hostname or IP, or a comma-separated list of
hostnames or IP addresses.  The option adds these hosts to the list.
Multiple options can be specified.
.PP
The \fB\-H\fR option exists mainly as a way of quickly running a job
of several hosts at once.  If you have a set of hosts which you often
work with, it's best to use a
.IR hostgroup .
.PP
Hostgroup defines a list of hosts and, optionally, a set of
.B rex
settings to use when running commands on them.  Each hostgroup is
identified by its name and is defined in a separate disk file.  See
the subsection \fBHostgroups\fR, for a detailed discussion of how to
define a hostgroup.
.PP
Once defined, the option \fB\-g\fR (\fB\-\-group\fR) can be used to
run a command on each host in the group.  The argument to the option
is the name of the group.  Thus, e.g.
.PP
.EX
rex run \-g\fINAME\fR \fICOMMAND\fR
.EE
.PP
runs \fICOMMAND\fR on hosts from hostgroup \fINAME\fR, and
.PP
.EX
rex copy \-g\fINAME\fR \fIFILE\fR /tmp
.EE
.PP
copies \fIFILE\fR to the directory \fB/tmp\fR on each host from this
hostgroup.
.PP
If the \fB\-g\fR option is omitted, \fBrex\fR will use the hostgroup
from the top of the hostgroup stack or, if it is empty, the
default hostgroup.
.PP
\fIHostgroup stack\fR is maintained using the \fBrex group\fR command.
Once the user pushes a hostgroup name on it, that hostgroup will be
used by any subsequent \fBrex\fR command, unless it is given the
\fB\-g\fR option.  The \fBrex group\fR command provides ways to pop
items off the stack, swap arbitrary element and the top of the stack,
select new hostgroups on the fly, etc.  See the section
.B REX GROUP
below for a detailed discussion of hostgroup stack.
.PP
The \fBdefault hostgroup\fR is used if the hostgroup stack is empty.
It is defined using the \fBoption group\fR statement in the
configuration file.
.PP
The list of hosts in a hostgroup can be modified for the duration of a
single \fBrex\fR command by using the \fB\-H\fR and \fB\-X\fR options.
The \fB\-H\fR (\fB\-\-host\fR) option works exactly as described
above.   The \fB\-i\fR (\fB\-\-ignore\-hosts\fR) option can be given
to ignore the list of hosts defined in the hostgroup and operate only
on those supplied with the \fB\-\-host\fR options.
.PP
The \fB\-X\fR (\fB\-\-exclude\fR) option instructs \fBrex\fR to remove
its argument from the list of hosts.  Its argument is the domain name
or IP address of the host.  It need not be exactly the same name
or IP as the one used in the \fBset hosts\fR statement in the \fBrc\fR
file.  It suffices that it resolves to the same IP as one of the hosts
listed in the hostgroup.
.PP
The list of all available hostgroups can be obtained using the
\fBlist\fR command.  The list is organized in two columns:
group name and its short description (if available).
.SS Login credentials
Normally, remote hosts should be configured to accept logins to the
user account without password, by using shared keys.  However, it is
also possible to work on hosts requiring password for authentication.
To do so, \fBrex\fR keeps the database of login credentials.  The
database is edited using the command
.PP
.EX
rex edit
.EE
.PP
This command starts the editor defined by the \fBVISUAL\fR (or, if
unset, \fBEDITOR\fR) environment variable.  Upon exit from the editor,
it compares the new content with the existing one.  If changed, the
user is prompted whether they wish to save the changes.
.PP
The database is a dictionary of \fIkey-value\fR pairs.  A key
identifies the credential (e.g. \fBuser\fR, for username, or
\fBpass\fR, for password).  Unless prefixed with one or more
\fIqualifiers\fR, it is valid for all servers in all hostgroups.
Qualifiers limit the scope of a key to a given hostgroup or server.
.PP
In general, the syntax for a key is:
.PP
.EX
[[\fIGROUP\fB:\fR][\fIHOST\fR]\fB:\fR]\fIKEYWORD\fR
.EE
.PP
When looking for a key, the most qualified match is preferred, so the
lookup order is:
.RS
.nr step 1 1
.IP \n[step].
\fIGROUP\fB:\fIHOST\fB:\fIKEYWORD\fR
.IP \n+[step].
\fIHOST\fB:\fIKEYWORD\fR
.IP \n+[step].
\fIGROUP\fB::\fIKEYWORD\fR
.IP \n+[step].
\fIKEYWORD\fR
.RE
.PP
For example, to determine the login name for the given host, \fBrex\fR
looks up for the keyword \fBuser\fR.  If no matching key is found
and the the \fB\-u\fR (\fB\-\-user\fR) option is given, its value is
used.  Otherwise, the name of the value of the environment variable
.B USER
is used.
.PP
Similarly, the password to use is determined by the following
look-ups:
.RS
.nr step 1 1
.IP \n[step].
\fIGROUP\fB:\fIHOST\fB:\fBpass\fR
.IP \n+[step].
\fIHOST\fB:pass\fR
.IP \n+[step].
\fIGROUP\fB::\fBpass\fR
.IP \n+[step].
\fBpass\fR
.RE
.PP
If none of these keys is found, the value of the \fB\-p\fR
(\fB\-\-password\fR) option is used.  If this option is not supplied
either, passwordless account is assumed.
.SS Configuration files
Upon startup \fBrex\fR looks for the following files and attempts to
source them:
.TP
.B \*(ET/rex/rc
System-wide configuration file.
.TP
.B ~/.rex/rc
User-specific configuration file.
.PP
These files are not required to exist.  If they do the user settings
override the system-wide ones.
.PP
These files are sourced as regular \fBTCL\fR code.  Normally, they
modify the \fBrex\fR settings by using a st of commands provided for
that purpose:
.TP
\fBhost\fR \fIHOSTNAME\fR [\fIHOSTNAME\fR...]
Adds the listed hostnames to the list of hosts.
.TP
\fBhostname\fR \fIIP\fR \fINAME\fR
Registers \fINAME\fR in DNS cache as a hostname for the IPv4
address \fIIP\fR. This is useful if \fIIP\fR has no PTR record, or its
PTR record is deemed unsuitable for some reason.
.TP
\fBifmode\fR \fB{\fR \fImode\fR \fIbody\fR [\fImode\fR \fIbody\fR...] \fB}\fR
Matches the current mode against each of \fImode\fR arguments.  As soon
as the match is found, the corresponding \fBbody\fR is evaluated.
Similarly to the
.BR switch (n)
command, a dash in place of \fIbody\fR means that the body for the
next mode should also be used as the body for this one.  If the next
mode has a body of \fB\(dq\-\(dq\fR, than the body after that is used,
etc.)  The \fImode\fR should be one of the following:
.BR run ,
.BR copy\-to ,
.BR copy\-from ,
.BR login ,
.BR list ,
and
.BR edit .
If the last mode used is the word \fBdefault\fR, it will match any
mode not explicitly listed before.

The \fBifmode\fR pattern allows for selecting different settings
depending on the running mode.  For example, it is common to set the
\fBTERM\fR environment variable to \fBdumb\fR for \fBrun\fR mode.
However, it is undesirable in \fBlogin\fR and \fBedit\fR modes, and
has no effect on the remaining modes.  To make sure it is set only for
\fBrun\fR mode, the following statement is normally used:
.RS
.EX
ifmode {
  run { environ TERM=dump }
}
.EE
.RE
.TP
\fBoption\fR \fIOPTNAME\fR \fIVALUE\fR [\fIVALUE\fR...]
Sets or unsets a \fBrex\fR option.  \fIOPTNAME\fR is the long name of
the option without the leading two dashes.  For example, setting
.RS
.EX
option jobs 25
.EE

has the same effect as giving the option \fB\-\-jobs=25\fR in the
command line.

Options that take no argument in the command line are treated as
booleans.  The \fIVALUE\fR of
.BR on ,
.BR true ,
.BR yes ,
or
.BR 1
sets the option, while the \fBVALUE\fR of
.BR off ,
.BR false ,
.BR no ,
or
.BR 0
unsets it.  Thus, to set the \fBno\-resolve\fR option, use
.EX
option no\-resolve true
.EE
.RE
.TP
\fBtimeout\fR [\fINUMBER\fR]
Sets the timeout for expecting reply from the remote commands.
\fINUMBER\fR is the timeout value in seconds.  When used without
arguments, returns the current timeout value.
.TP
\fBenviron\fR [\fB\-set\fR] \fINAME\fB=\fIVALUE\fR [\fINAME\fB=\fIVALUE\fR...]
Sets environment variables.
.TP
\fBenviron -unset\fR \fINAME\fR [\fINAME\fR...]
Unsets environment variables.
.TP
\fBearlycmd\fR [\fB\-clear\fR] \fICOMMAND\fR [\fICOMMAND\fR...]
Defines the sequence of shell commands that will be sent as soon as
the secure connection to the remote host is established, before
waiting for the command line prompt.  For an example of its use,
see the note about \fBZSH\fR, below.
.TP
\fBshrc\fR [\fB\-clear\fR] \fICOMMAND\fR [\fICOMMAND\fR...]
Defines the sequence of shell commands that will be sent after
receiving the first command line prompt from the remote server.
.SS Hostgroups
A \fIhostgroup\fR defines a list of hosts and optionally associates
a set of
.B rex
settings to use when running commands on them.  Each hostgroup is
identified by its name, which must comply with the same requirements
as a name of a disk file.  The hostgroup definition consists of one or
more files located in the directory \fB~/.rex/hostgroup/\fINAME\fR
(user-specific), or \fB\*(ET/rex/hostgroup/\fINAME\fR (system-wide), where
\fINAME\fR is the name of the group.  User-specific directories are
given preference over the system-wide ones.  The only mandatory file is
\fBrc\fR.  It is a \fBTCL\fR source, which will be loaded in a
separate namespace, to avoid the possibility of inadvertent
contamination of the main \fBrex\fR code.
.PP
The hostgroup \fBrc\fR file should use the \fBhost\fR and/or
\fBhostgroup\fR commands 
(see the subsection
.B Configuration files
above) to define the list of hosts in the hostgroup.
.SS Debugging
To see what's going on during \fBrex\fR invocation, use the
\fB\-d (\fB\-\-debug\fR) option.  This option is incremental, that is
the more times you repeat it in the command line, the more debugging
information is output.  Currently, the most detailed information is
obtained at level 3, i.e. using \fB\-ddd\fR.
.PP
Additional information is provided by the \fB\-l\fR
(\fB\-\-log\fR) option, which enables logging of the send/expect
dialog to stdout.
.PP
If you wish to get even more information and are familiar with
.BR expect (1)
internals, set the
.B EXPECT_DEBUG
environment variable prior to invoking \fBrex\fR.  The value of this
variable is the name of a file where to output additional information
(as well as showing it on the standard error).  Overall effect is
equivalent to setting \fBexp_internal\fR in
.BR expect .
.PP
When \fBrex\fR encounters an error in one of its rc files, it prints
the location where the error occurred and a short diagnostic message
describing the nature of the error.  If you wish to obtain full trace
of TCL calls for such errors, use the 
.B \-\-tcl\-trace
option.  Normally, this option is only useful for \fBrex\fR developers.
.SH OPTIONS
.TP
\fB\-c\fR, \fB\-\-config=\fIFILE\fR
Read configuration from \fIFILE\fR.
.TP
.BR \-d ", " \-\-debug
Increase debugging level.
.TP
.BR \-l ", " \-\-log
Log everything to the standard output.
.TP
\fB\-q\fR, \fB\-\-no\-init\-file\fR, \fB\-\-no\-rc\-file\fR
Don't read system-wide and user configuration files.
.TP
.BR \-N ", " \-\-noop
Ignore all commands (useful for side effects).
.TP
.BR \-n ", " \-\-no\-resolve
Don't resolve IP addresses when printing hostnames.
.TP
.B \-\-tcl\-trace
Produce full TCL trace if an error occurs while sourcing one of the
configuration files.  This option is useful mainly for developers.
.TP
\fB\-v\fR, \fB\-\-verbose\fR
Enable additional warnings.
.TP
.BR \-V ", " \-\-version
Print program version and copyright statement.
.TP
.BR \-h ", " \-\-help
Show a terse help summary
.SH REX RUN
.EX
\fBrex run \fIPROGRAM\fR \fIARG\fR [\fIARG\fR...]
.EE
.PP
The \fBrex run\fR command runs the specified program with the
arguments on the servers.
.PP
.SS Sequential and parallel execution
By default, \fBrex run\fR executes the command on each host in
succession.  The output from the command is printed on the standard 
output, preceded by a header line containing the name of the remote host
that produced the output, and a colon.
.PP
The \fB\-\-no\-host\-header\fR option disables printing of that header
line.  The \fB\-P\fR (\fB\-\-prefix\fR) option further modifies the
output by prefixing each line with the hostname, a greater than sign,
and a space character.
.PP
When operating on a big number of hosts, the operation can be sped up
by running command on several hosts at once.  This parallel operation
is enabled by the \fB\-j\fIN\fR (\fB\-\-jobs=\fIN\fR) option.  The
\fIN\fR parameter is the number of hosts to be processed in a batch.
.PP
The \fB\-j\fR option implies \fB\-\-prefix \-\-no\-host\-header\fR
to make it clear which host produced which line.  However, if the
command produces multiple lines of output, they become intermixed when
running in parallel.  To further improve readability of the output,
the \fB\-b\fR (\fB\-\-buffer\-output\fR) option is provided.
.PP
This option instructs \fBrex\fR to buffer output from each host in the
batch and to output it only after the host closes connection.  This
way, output from each host appears on screen as a contiguous text.
.PP
The \fB\-b\fR option cancels the implied \fB\-\-prefix
\-\-no\-host\-header\fR settings.
.SS Transferring data prior to execution
If the program relies on some additional files to be present, these can
be transferred to each host prior to running the program.  The
transfer is requested by the \fB\-D\fR (\fB\-\-data\-file\fR) option.
The argument to this option names the file to be copied to the target host.
.PP
To transfer multiple files, repeat the \fB\-D\fR option for each of
them.
.PP
The files supplied with the \fB\-D\fR options will be copied to a
temporary directory created in \fB/tmp\fR on each target host.  That
directory will become current working directory when invoking the
\fIPROGRAM\fR.
.PP
The arguments to \fIPROGRAM\fR can refer to the files transferred via
the \fB\-D\fR option using the syntax \fB{\fIN\fB}\fR, where \fIN\fR
is the number of the \fB\-D\fR option occurrence (1-based).  The
\fB{\fIN\fB}\fR is expanded to the file name part of the argument to
the corresponding \fB\-D\fR option.  For example,
.PP
.EX
rex run \-D prefix.txt \-D repl sed \-f {2} {1} /etc/passwd
.EE
.PP
will result in running the following command in a temporary directory
on each target host:
.PP
.EX
sed \-f repl prefix.txt /etc/passwd
.EE
.PP
Note, that the \fB{\fIN\fB}\fR notation expands to a file name relative to
the current working directory on the remote host.  This means that
.PP
.EX
rex run \-D /tmp/prefix.txt \-D repl sed \-f {2} {1} /etc/passwd
.EE
.PP
will result in exactly the same command as the example above: the
expansion of \fB{1}\fR will throw away the directory part from the
file name.
.PP
Similarly, the token \fB{}\fR expands to a space-separated
list of file names passed with all \fB\-D\fR options, in the same
order they appear on the command line. 
.PP
The \fIPROGRAM\fR itself can be an interpreted script that needs to be
copied on each host for execution.  The \fB\-\-copy\fR option
instructs \fBrex\fR to create a temporary directory on the remote
host, copy \fIPROGRAM\fR there, and then select the interpreter to run
by analyzing the first line from it.  If this line starts with
characters \fB#!\fR, the rest of line is taken as the interpreter
pathname and initial arguments.  For example, assuming that file
\fB/libexec/foo\fR is a shell script beginning with \fB#!/bin/ksh\fR,
the following command:
.PP
.EX
rex run \-\-copy /libexec/foo /home
.EE
.PP
will first copy the file \fB/libexec/foo\fR to a temporary
directory on the remote host, and then invoke it as
.PP
.EE
/bin/ksh foo /home
.EX
.PP
If the file does not begin with \fB#!\fR, the default interpreter,
\fB/bin/sh\fR, will be used.  The default interpreter can be changed
using the \fB\-\-interpreter\fR option, as in the following example:
.PP
.EX
rex run \-\-copy \-\-interpreter="/bin/env perl" test.pl
.EE
.SS Scripting
When given the \fB\-s \fINAME\fR option, \fBrex run\fR looks for the file
named \fINAME\fB\.tcl\fR in the library search path.  The search path
is scanned from left to right.  The first encountered
\fINAME\fB\.tcl\fR file is sourced in the namespace \fBhostproc\fR.
.PP
The default library search path is:
.PP
.RS
.B ~/.rex/script
.br
.B \*(ET
.RE
.PP
If the \fB\-g \fIGROUP\fR (\fB\-\-group=\fIGROUP\fR) option is given,
the path is modified as follows:
.PP
.RS
\fB~/.rex/\fIGROUP\fB/script\fR
.