Guest User

Untitled

a guest
Dec 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use DBI;
  5. use Getopt::Long;
  6.  
  7. print "Content-type: text/plain";
  8. print "\n\n";
  9.  
  10. # remote
  11. my $local_dsn = "DBI:mysql:database=somedatabase;host=THE_IP;port=11912";
  12. my $local_username = "someusername";
  13. my $local_password_file_fn = "/home/server/remote_stats/local_password_file.txt";
  14. my $local_table_name = "characters";
  15. my $local_col_name = "online";
  16.  
  17. # local
  18. my $remote_dsn = "DBI:mysql:database=l2worldo_stats;host=localhost;port=3306";
  19. my $remote_username = "anotherusername";
  20. my $remote_password_file_fn = "/home/server/remote_stats/remote_password_file.txt";
  21. my $remote_table_name = "stats_online";
  22. my $remote_col_name = "online_users";
  23. my $server_name = "x15";
  24.  
  25. my $local_password;
  26. {
  27. open my $p_fh, "<", $local_password_file_fn
  28. or die "Could not open password filename - '$local_password_file_fn' for reading";
  29. $local_password = <$p_fh>;
  30. chomp($local_password);
  31. close($p_fh);
  32. }
  33.  
  34. my $remote_password;
  35. {
  36. open my $p_fh, "<", $remote_password_file_fn
  37. or die "Could not open password filename - '$remote_password_file_fn' for reading";
  38. $remote_password = <$p_fh>;
  39. chomp($remote_password);
  40. close($p_fh);
  41. }
  42.  
  43. my $local_dbh = DBI->connect($local_dsn, $local_username, $local_password);
  44. my $local_sth = $local_dbh->prepare("SELECT SUM(online) FROM $local_table_name WHERE $local_col_name = 1");
  45. $local_sth->execute();
  46.  
  47. my $remote_dbh = DBI->connect($remote_dsn, $remote_username, $remote_password);
  48. my $remote_sth = $remote_dbh->prepare("UPDATE `$remote_table_name` SET `$remote_col_name` = (?) WHERE (`server_name` = '$server_name')");
  49. while (my ($value) = $local_sth->fetchrow_array()) {
  50. $remote_sth->execute(int($value * 1.5));
  51. }
  52.  
  53. $local_dbh->disconnect();
  54. $remote_dbh->disconnect();
Add Comment
Please, Sign In to add comment