#!/usr/bin/perl -w # # $Id: tokenwatch,v 1.6 2008/02/11 18:06:25 rader Exp $ # use strict; use POSIX ":sys_wait_h"; my $okay_sleep = 5; my $no_token_sleep = 2; my $msg = "Your afs token has expired!"; my $font = '-f "-adobe-helvetica-bold-r-normal--*-240-*-*-*-*-*-*"'; my $tokens = "/usr/bin/tokens"; my $osd_cat = "/usr/bin/osd_cat"; my $args = "-d 1 -p bottom -O 2 -l 1 --age=1"; my $afs_token = 0; if ( ! -x "$osd_cat" ) { print "tokenwatch failed: $osd_cat: no such file\n"; exit 1; } my $cell = `fs wscell`; chop $cell; $cell =~ s/.*\'(.*?)'.*/$1/; $| = 1; my $pid = open(OSD,"|$osd_cat $args $font"); close(STDIN); close(STDOUT); close(STDERR); while (1) { # if osd_cat has exited, then exit... my $child_id = waitpid($pid, WNOHANG); if ( $child_id == $pid ) { exit; } &check_token; while ( ! $afs_token ) { print OSD $msg . "\n"; sleep $no_token_sleep; &check_token; } sleep $okay_sleep; } close(OSD); exit; #------------------------------------------------------------------ sub check_token { $afs_token = 0; open(IN,"$tokens|"); while () { if ( $_ =~ /User\'s .*? tokens for afs\@$cell/ ) { $afs_token = 1; } } close(IN); }