Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #use strict;
  4. use warnings;
  5.  
  6. use DBI;
  7.  
  8. use Getopt::Long;
  9.  
  10. #local stuff
  11. my $local_table_name;
  12. my $local_dsn;
  13. my $local_password_file_fn;
  14. my $local_username;
  15. my $local_col_name;
  16.  
  17. #remote stuff
  18. my $remote_table_name;
  19. my $remote_dsn;
  20. my $remote_password_file_fn;
  21. my $remote_username;
  22. my $remote_col_name;
  23.  
  24. if (!GetOptions(
  25. "local_table=s" => \$local_table_name,
  26. "local_dsn=s" => \$local_dsn,
  27. "local_username:s" => \$local_username,
  28. "local_password-file=s" => \$local_password_file_fn,
  29. "local_column-name=s" => \$local_col_name,
  30. "remote_table=s" => \$remote_table_name,
  31. "remote_dsn=s" => \$remote_dsn,
  32. "remote_username:s" => \$remote_username,
  33. "remote_password-file=s" => \$remote_password_file_fn,
  34. "remote_column-name=s" => \$remote_col_name,
  35. ))
  36. {
  37. die "You did not specify everything on the command line !";
  38. }
  39.  
  40. my $local_password;
  41. {
  42. open my $p_fh, "<", $local_password_file_fn
  43. or die "Could not open password filename - '$local_password_file_fn' for reading";
  44. $local_password = <$p_fh>;
  45. chomp($local_password);
  46. close($p_fh);
  47. }
  48.  
  49. my $remote_password;
  50. {
  51. open my $p_fh, "<", $remote_password_file_fn
  52. or die "Could not open password filename - '$remote_password_file_fn' for reading";
  53. $remote_password = <$p_fh>;
  54. chomp($remote_password);
  55. close($p_fh);
  56. }
  57.  
  58. # local statements
  59. my $local_dbh = DBI->connect($local_dsn, $local_username, $local_password);
  60. my $local_sth = $local_dbh->prepare("SELECT SUM(online) FROM $local_table_name WHERE $local_col_name = 1");
  61. $local_sth->execute();
  62.  
  63. # remote
  64. my $remote_dbh = DBI->connect($remote_dsn, $remote_username, $remote_password);
  65. my $remote_sth = $remote_dbh->prepare("INSERT INTO `x20` ('online_users') VALUES ('$value')");
  66.  
  67. while (my ($value) = $local_sth->fetchrow_array())
  68. {
  69. $remote_sth->execute();
  70. }
  71.  
  72. $local_dbh->disconnect();
  73. $remote_dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement