#!/usr/bin/perl -w use strict; use File::stat; use POSIX; POSIX::nice 20 or die; &play, exit 0 if (scalar @ARGV); close STDIN; open STDIN, "/dev/null" or die; close STDERR; open STDERR, ">/dev/null" or die; exit 0 if fork; my $ino = 0; my $size = 0; my $mute; my $volume; while (1) { my $sb = stat("/var/mail/".$ENV{'USER'}); &got_mail if ($ino && $sb->size > $size); $ino = $sb->ino; $size = $sb->size; sleep 1; } sub got_mail { my @time = localtime time; my $time = $time[2] * 60 + $time[1]; if ($time[6] >= 1 and $time[6] <= 5) { return if ($time < 8.5 * 60 || $time > 19 * 60); } else { return; } &play; } sub play { &sysctl_a; system("mixerctl -w outputs.mono.mute=off"); system("mixerctl -w outputs.mono=160"); system("play ~folays/pub/sound/Got_Mail.wav"); &sysctl_w; } sub sysctl_a { $mute = `mixerctl -n outputs.mono.mute`; $volume = `mixerctl -n outputs.mono`; } sub sysctl_w { system("mixerctl -w outputs.mono.mute=$mute"); system("mixerctl -w outputs.mono=$volume"); }