Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #use strict;
- use warnings;
- use DBI;
- use Getopt::Long;
- #local stuff
- my $local_table_name;
- my $local_dsn;
- my $local_password_file_fn;
- my $local_username;
- my $local_col_name;
- #remote stuff
- my $remote_table_name;
- my $remote_dsn;
- my $remote_password_file_fn;
- my $remote_username;
- my $remote_col_name;
- if (!GetOptions(
- "local_table=s" => \$local_table_name,
- "local_dsn=s" => \$local_dsn,
- "local_username:s" => \$local_username,
- "local_password-file=s" => \$local_password_file_fn,
- "local_column-name=s" => \$local_col_name,
- "remote_table=s" => \$remote_table_name,
- "remote_dsn=s" => \$remote_dsn,
- "remote_username:s" => \$remote_username,
- "remote_password-file=s" => \$remote_password_file_fn,
- "remote_column-name=s" => \$remote_col_name,
- ))
- {
- die "You did not specify everything on the command line !";
- }
- my $local_password;
- {
- open my $p_fh, "<", $local_password_file_fn
- or die "Could not open password filename - '$local_password_file_fn' for reading";
- $local_password = <$p_fh>;
- chomp($local_password);
- close($p_fh);
- }
- my $remote_password;
- {
- open my $p_fh, "<", $remote_password_file_fn
- or die "Could not open password filename - '$remote_password_file_fn' for reading";
- $remote_password = <$p_fh>;
- chomp($remote_password);
- close($p_fh);
- }
- # local statements
- my $local_dbh = DBI->connect($local_dsn, $local_username, $local_password);
- my $local_sth = $local_dbh->prepare("SELECT SUM(online) FROM $local_table_name WHERE $local_col_name = 1");
- $local_sth->execute();
- # remote
- my $remote_dbh = DBI->connect($remote_dsn, $remote_username, $remote_password);
- my $remote_sth = $remote_dbh->prepare("INSERT INTO `x20` ('online_users') VALUES ('$value')");
- while (my ($value) = $local_sth->fetchrow_array())
- {
- $remote_sth->execute();
- }
- $local_dbh->disconnect();
- $remote_dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement