When my son wants to use the computer, we generally let him do so for a predetermined period of time (maybe a half hour or an hour). Trouble arises when he "forgets" when he logged in or "loses track of time".

So I wrote this script to remind him how long he has been logged in. It pops up a reminder in KDE after 30, 60, 90 and 120 minutes letting him know how long he has been using the computer.

As an added bonus, it sends a text to my phone at 2 hours, just incase the computer was left on.

#!/usr/local/bin/perl use strict; use warnings; use Carp; use User; use Sys::Lastlog; use Time::localtime; my $ll = Sys::Lastlog->new(); my $llent = $ll->getllnam( User->Login ); my $tm = localtime( $llent->ll_time() ); my $login_time = sprintf( "%02d:%02d:%02d on %04d/%02d/%02d", $tm->hour, $tm->min, $tm->sec, $tm->year + 1900, $tm->mon + 1, $tm->mday ); my %actions = ( 1800 => sub { passive_pop("Thirty minutes"); }, 3600 => sub { passive_pop("One hour"); }, 5400 => sub { passive_pop("One hour thirty minutes"); }, 7200 => sub { passive_pop("Two hours"); tattle_tail(); }, ); for my $duration ( sort { $a <=> $b } keys %actions ) { sleep 1 until time - $llent->ll_time >= $duration; $actions{$duration}->(); } sub passive_pop { my $m = shift @_; my @args = ( "kdialog", "--passivepopup", $m . " has passed since you logged in at:\n " . + $login_time, "120" ); system(@args) == 0 or croak "system @args failed: $?"; return; } sub tattle_tail { use MIME::Lite; my $msg = MIME::Lite->new( From => 'tattle_tail@domain.com', To => 'text@domain.com', Subject => 'The computer may have been left on', Data => 'Childname logged in at ' . $login_time, ); $msg->send; return; }

Improvements and comments welcome.

KennV

Updated to reflect blokheads suggestions.
Thanks blokhead!!

In reply to Reminder for KDE Kid by KennV

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.