Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/user/bin/bash
- use warnings;
- use strict;
- use DBI;
- use Data::Dumper;
- #Script location
- my $speedtest_cmd #!/user/bin/bash
- use warnings;
- use strict;
- use DBI;
- use Data::Dumper;
- #Script location
- my $speedtest_cmd = '/usr/bin/speedtest-cli --simple';
- #Holds metrics we want to go in DB
- my @metrics;
- #Holds results of test
- my @results
- #DB connection params
- my $db_host = '127.0.0.1';
- my $db_user = 'username';
- my $db_passwd = 'pwd';
- # DB to insert into.
- my $db_name = 'speedtest';
- my $db_table = 'results';
- foreach my $line ('$speedtest_cmd') {
- if ($line =~ /^(\w+):\s([\d\.]+)\s/) {
- push(@metrics, lc($1));
- push(@results, lc($2));
- }
- }
- if (!@metrics || !@results) {
- die "There was an error capturing output of the speedtest script.\n";
- }
- foreach my $line ('$speedtest_cmd') {
- if ($line =~ /^(\w+):\s([\d\.]+)\s/) {
- push(@metrics, lc($1));
- push(@results, lc($2));
- }
- }
- foreach my $line ('$speedtest_cmd') {
- if ($line =~ /^(\w+):\s([\d\.]+)\s/) {
- push(@metrics, lc($1));
- push(@results, lc($2));
- }
- }
- if (!@metrics || !@results) {
- die "There was an error capturing output of the speedtest script.\n";
- }
- my $dbh = DBI->connect("DBI:mysql:$db_name", $db_user, $db_passwd, {RaiseError => 1});
- my $sql = "INSERT INTO $db_table (" . join(', ', @metrics) . ") VALUES (?, ?, ?)";
- my $sth = $dbh->prepare($sql);
- $sth->execute(@results);
- $sth->finish();
- $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement