Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl -w
- use strict;
- use warnings;
- use DBI;
- use Getopt::Long;
- print "Content-type: text/plain";
- print "\n\n";
- # remote
- my $local_dsn = "DBI:mysql:database=somedatabase;host=THE_IP;port=11912";
- my $local_username = "someusername";
- my $local_password_file_fn = "/home/server/remote_stats/local_password_file.txt";
- my $local_table_name = "characters";
- my $local_col_name = "online";
- # local
- my $remote_dsn = "DBI:mysql:database=l2worldo_stats;host=localhost;port=3306";
- my $remote_username = "anotherusername";
- my $remote_password_file_fn = "/home/server/remote_stats/remote_password_file.txt";
- my $remote_table_name = "stats_online";
- my $remote_col_name = "online_users";
- my $server_name = "x15";
- 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);
- }
- 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();
- my $remote_dbh = DBI->connect($remote_dsn, $remote_username, $remote_password);
- my $remote_sth = $remote_dbh->prepare("UPDATE `$remote_table_name` SET `$remote_col_name` = (?) WHERE (`server_name` = '$server_name')");
- while (my ($value) = $local_sth->fetchrow_array()) {
- $remote_sth->execute(int($value * 1.5));
- }
- $local_dbh->disconnect();
- $remote_dbh->disconnect();
Add Comment
Please, Sign In to add comment