#!/usr/bin/perl -w #----------------------------------------------------------------# # The purpose of this script is to monitor the activity on a # # terminal. if the terminal is idle, it will send a text string # # or a null to the tty to keep the session open. Once the # # terminal is no longer idle it will sleep and test again in # # $loop seconds. # #----------------------------------------------------------------# use strict; use POSIX; my $loop = shift || 20; # number of seconds between checks my $sec_old = shift || 60; # number of seconds since data has # come through the port tty my $verbose = shift; # check for verbose output my $tty = ttyname(1); # '1' is the file descriptor for STDOUT my $total_sleep_seconds = 0; $|++; warn "\nHold time reporting is not accurate when loop", " seconds ( $loop ) ", "are greater than seconds old ", "( $sec_old )\n" if ( $loop > $sec_old ); while (1){ my $age = time() - eval((stat($tty))[9]); if ( $age > $sec_old){ $total_sleep_seconds += $age; print "Holding Session $total_sleep_seconds seconds.\n" if (defined $verbose); print "\0" if (! (defined $verbose)); } elsif ($age < $loop){ $total_sleep_seconds = 0; } sleep $loop; }