Command-line history logging utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.2 KiB

  1. =pod
  2. =head1 NAME
  3. App::CommandLog - Tools for logging command line history
  4. =head1 INSTALLING
  5. $ perl Build.PL
  6. $ ./Build
  7. $ ./Build install
  8. =cut
  9. package App::CommandLog;
  10. our ($VERSION) = '0.5.0';
  11. use strict;
  12. use warnings;
  13. use DBI;
  14. =over
  15. =item get_dbh()
  16. Get database handle for default commandlog database.
  17. =cut
  18. sub get_dbh {
  19. my $dbfile = $ENV{HOME} . "/cli.db";
  20. my $init_new = 0;
  21. $init_new = 1 unless -f $dbfile;
  22. my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
  23. # Make a new database and table(s), if needed:
  24. create_log_db($dbh) if $init_new;
  25. return $dbh;
  26. }
  27. =item create_log_db()
  28. Create SQLite log database.
  29. =cut
  30. sub create_log_db {
  31. # TODO: maybe log exit status, timing, memory, load, distro
  32. my ($dbh) = @_;
  33. $dbh->do(<<'SQL'
  34. CREATE TABLE commands (
  35. id integer primary key,
  36. command text,
  37. expanded_command text,
  38. path text,
  39. hostname text,
  40. username text,
  41. shell text,
  42. terminal text,
  43. notes text,
  44. datetime text
  45. );
  46. SQL
  47. );
  48. }
  49. =back
  50. =head1 AUTHOR
  51. Copyright 2016-2019 Brennen Bearnes
  52. commandlog is free software: you can redistribute it and/or modify
  53. it under the terms of the GNU General Public License as published by
  54. the Free Software Foundation, either version 3 of the License, or
  55. (at your option) any later version.
  56. commandlog is distributed in the hope that it will be useful,
  57. but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  59. GNU General Public License for more details.
  60. You should have received a copy of the GNU General Public License
  61. along with commandlog. If not, see <https://www.gnu.org/licenses/>.
  62. commandlog is free software; you can redistribute it and/or modify
  63. it under the terms of the GNU General Public License as published by
  64. the Free Software Foundation; either version 3 of the License, or
  65. (at your option) any later version.
  66. This program is distributed in the hope that it will be useful,
  67. but WITHOUT ANY WARRANTY; without even the implied warranty of
  68. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  69. GNU General Public License for more details.
  70. =cut
  71. 1;