-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_status.pl
executable file
·39 lines (32 loc) · 1023 Bytes
/
check_status.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl -w
use strict;
use IO::Handle;
#use Proc::Daemon;
# Don't daemonize if you're running this as a launch agent!
my $monitor_user = 'goerz';
my $timelimit = 3800;
sub notify{
my $program_name = "/usr/local/bin/growlnotify -s -t 'Activity Logger Error' > /dev/null 2>&1";
open(PIPE, "| $program_name") or die("Can't open pipe");
print PIPE "Last activity was recorded more then $timelimit seconds ago\n";
close(PIPE)
}
my $log_folder = '/Users/'. $monitor_user . '/.activity_logs';
my ($sec,$min,$hour,$mday,
$month,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
$month = sprintf("%02i", $month+1);
my $log_file = $log_folder . '/' . 'activity' . $year . '-' . $month . '.log';
open(IN, $log_file) or die("Can't open $log_file\n");
my $timediff = $timelimit + 1;
while (<IN>){
if ( /^([0-9]+)\t(0|1|-1)\t(.*)$/ ){
$timediff = time() - $1;
} else {
die ("Couldn't parse line:\n$_");
}
}
if ($timediff > $timelimit){
notify();
}
close(IN);