Wed Mar 16 21:15:14 PST 2005
- Previous message: [Slony1-commit] By smsimms: Add an option to only kill watchdogs, not slons.
- Next message: [Slony1-commit] By cbbrowne: cleanup thread uses Slony-I stored procedure getMinXid()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message:
-----------
Added a "-c" to execute_script.pl, a la psql. If you only want to run
a small number of commands, this saves you the trouble of putting them
into a file first.
Removed the "node#" argument since this is derivable. Replaced it
with a --node option so that it can be overridden if necessary.
Added an error check to make sure the set exists in the configuration
file.
Modified Files:
--------------
slony1-engine/tools/altperl:
execute_script.pl (r1.1 -> r1.2)
-------------- next part --------------
Index: execute_script.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/execute_script.pl,v
retrieving revision 1.1
retrieving revision 1.2
diff -Ltools/altperl/execute_script.pl -Ltools/altperl/execute_script.pl -u -w -r1.1 -r1.2
--- tools/altperl/execute_script.pl
+++ tools/altperl/execute_script.pl
@@ -8,17 +8,35 @@
# Defaults
$CONFIG_FILE = '@@SYSCONFDIR@@/slon_tools.conf';
$SHOW_USAGE = 0;
+$SCRIPT_ARG = "";
+
+# Allow this to be specified. Otherwise it will be pulled from
+# the get_set function.
+$node = 0;
# Read command-line options
GetOptions("config=s" => \$CONFIG_FILE,
- "help" => \$SHOW_USAGE);
+ "help" => \$SHOW_USAGE,
+ "c=s" => \$SCRIPT_ARG,
+ "n|node=s" => \$node);
my $USAGE =
-"Usage: execute_script [--config file] set# node# full_path_to_sql_script_file
-
- Executes the contents of a SQL script file on the specified set and node.
-
- The script only needs to exist on the machine running the slon daemon.
+"Usage:
+ execute_script [options] set# full_path_to_sql_script_file
+ execute_script [options] -c SCRIPT set#
+
+ Executes the contents of a SQL script file on the specified set.
+ The script only needs to exist on the machine running the slon
+ daemon.
+
+ set# The set to which this script applies.
+
+ -c SCRIPT Pass the SQL to be executed via the command line instead
+ of as a file.
+
+ -n NUM
+ --node=NUM Override the set origin specified in the configuration
+ file.
";
@@ -30,7 +48,7 @@
require '@@PGLIBDIR@@/slon-tools.pm';
require $CONFIG_FILE;
-my ($set, $node, $file) = @ARGV;
+my ($set, $file) = @ARGV;
if ($set =~ /^(?:set)?(\d+)$/) {
$set = $1;
} else {
@@ -38,15 +56,27 @@
die $USAGE;
}
-if ($node =~ /^(?:node)?(\d+)$/) {
- $node = $1;
-} else {
- print "Invalid node identifier\n\n";
- die $USAGE;
-}
+get_set($set) or die "Non-existent set specified.\n";
+$node = $SET_ORIGIN unless $node;
+# We can either have -c SCRIPT or a filename as an argument. The
+# latter takes precedence.
+if ($file) {
unless ($file =~ /^\// and -f $file) {
- print "SQL script path needs to be a full path, e.g. /tmp/my_script.sql\n\n";
+ print STDERR "SQL script path needs to be a full path, e.g. /tmp/my_script.sql\n\n";
+ die $USAGE;
+ }
+}
+elsif ($SCRIPT_ARG) {
+ # Put the script into a file
+ $file = "/tmp/execute_script.sql.$$";
+ my $fh;
+ open $fh, ">", $file;
+ print $fh $SCRIPT_ARG;
+ close $fh;
+}
+else {
+ print STDERR "You must include either a filename or a SQL statement on the command line to be run.\n\n";
die $USAGE;
}
- Previous message: [Slony1-commit] By smsimms: Add an option to only kill watchdogs, not slons.
- Next message: [Slony1-commit] By cbbrowne: cleanup thread uses Slony-I stored procedure getMinXid()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list