summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5bc2c37)
. Added another greeting to announceEmail.pl
. Removed a Perl::Critic warning for Unils.pm
. Changed message for Speak to use [silent]
. Created announceEmail sleep script
Actually not a sleep script but rather it is a script that needs to be
added to /lib/systemd/systemd-sleep (symlinked) so that when Ubuntu
20.04 comes out of suspend mode a USR2 signal is sent to all
announceEmail.pl processes. They then wake up and reconnect to their
IMAP hosts. This is necessary because the network is down during suspend
and Mail::IMAPTalk doesn't notice this so email announcements stop
happening. If instead Mail::IMAPTalk would have noticed this and
returned an error I could re-establish the connection in
announceEmail.pl but it doesn't.
Notice also that it takes 10-30 seconds to re-establish the network
connection after suspend so we just put a 60 second sleep in this script
rather than implementing a more complicated polling loop looking for the
network to come back up.
--- /dev/null
+#!/bin/bash
+case $1 in
+ post)
+ # If we send the USR2 signal before the network comes back up then
+ # announceEmail.pl will die trying to re-establish its connection to the
+ # IMAP server. So instead we use this cheap method of sleeping for a minute
+ # as the network should be back by then. A better method would be to poll
+ # looking for the network to come back up but that's tricker to implement.
+ sleep 60
+ killall -USR2 announceEmail.pl
+ ;;
+esac
-h|elp Detailed help
-v|erbose Verbose mode (Default: -verbose)
-de|bug Turn on debugging (Default: Off)
-h|elp Detailed help
-v|erbose Verbose mode (Default: -verbose)
-de|bug Turn on debugging (Default: Off)
-user|name User name to log in with (Default: $USER)
-p|assword Password to use (Default: prompted)
-i|map IMAP server to talk to (Default: defaria.com)
-user|name User name to log in with (Default: $USER)
-p|assword Password to use (Default: prompted)
-i|map IMAP server to talk to (Default: defaria.com)
-uses|sl Whether or not to use SSL to connect (Default: False)
-useb|locking Whether to block on socket (Default: False)
-uses|sl Whether or not to use SSL to connect (Default: False)
-useb|locking Whether to block on socket (Default: False)
+ Signals:
+ $SIG{USR1}: Toggles debug option
+ $SIG{USR2}: Reestablishes connection to IMAP server
+
=head1 DESCRIPTION
This script will connect to an IMAP server, login and then monitor the user's
=head1 DESCRIPTION
This script will connect to an IMAP server, login and then monitor the user's
'I was looking in your inbox and found a message',
'Not sure you want to hear this message',
'Good news',
'I was looking in your inbox and found a message',
'Not sure you want to hear this message',
'Good news',
+ "What's this? A new message",
+sub Connect2IMAP;
+
+sub restart {
+ $log->dbug("Re-establishing connection to $opts{imap} as $opts{username}");
+ Connect2IMAP;
+
+ goto MONITORMAIL;
+} # restart
+
$SIG{USR1} = \&interrupted;
$SIG{USR1} = \&interrupted;
sub unseenMsgs() {
$IMAP->select('inbox') or
sub unseenMsgs() {
$IMAP->select('inbox') or
sub Connect2IMAP() {
$log->dbug("Connecting to $opts{imap} as $opts{username}");
sub Connect2IMAP() {
$log->dbug("Connecting to $opts{imap} as $opts{username}");
+ # Destroy any old connections
+ undef $IMAP;
+
$IMAP = Mail::IMAPTalk->new(
Server => $opts{imap},
Username => $opts{username},
$IMAP = Mail::IMAPTalk->new(
Server => $opts{imap},
Username => $opts{username},
# If we return from idle then the server went away for some reason. With Gmail
# the server seems to time out around 30-40 minutes. Here we simply reconnect
# to the imap server and continue to MonitorMail.
# If we return from idle then the server went away for some reason. With Gmail
# the server seems to time out around 30-40 minutes. Here we simply reconnect
# to the imap server and continue to MonitorMail.
- $log->dbug("MonitorMail: Connection to $opts{imap} ended - lasted "
- . howlong $startTime);
-
- # Destroy current IMAP connection
- $log->dbug("MonitorMail: Destroying IMAP connection to $opts{imap}");
- undef $IMAP;
-
- # Re-establish connection
- Connect2IMAP;
-
- $log->dbug("MonitorMail: Reconnected to IMAP server $opts{imap}");
-
- # MonitorMail again - the dreaded goto! Seems the cleanest way to restart
- # in this instance. I could call MonitorMail() recursively but that would
- # leave junk on the stack.
- $log->dbug('MonitorMail: Going back to the top of the loop');
-
- goto MONITORMAIL;
-
- return; # To make perlcritic happy
# Call old signal handler (if any)
&$oldHandler if $oldHandler;
# Call old signal handler (if any)
&$oldHandler if $oldHandler;
Sends a command to the cleartool coprocess. If not running a cleartool coprocess
is started and managed. The coprocess is implemented as a coprocess using IPC
for communication that will exist until the object is destroyed. Stdin and
Sends a command to the cleartool coprocess. If not running a cleartool coprocess
is started and managed. The coprocess is implemented as a coprocess using IPC
for communication that will exist until the object is destroyed. Stdin and
-stdout/stderr are therefore pipes and can be fed. The execute method feds the
+stdout/stderr are therefore pipes and can be fed. The execute method feeds the
input pipe and returns status and output from the output pipe.
Using execute can speed up execution of repeative cleartool invocations
input pipe and returns status and output from the output pipe.
Using execute can speed up execution of repeative cleartool invocations
# Simple check to see if we can execute cleartool
@output = `$cleartool -ver 2>&1`;
@output = ();
# Simple check to see if we can execute cleartool
@output = `$cleartool -ver 2>&1`;
@output = ();
return (-1, 'Clearcase not installed')
unless $? == 0;
return (-1, 'Clearcase not installed')
unless $? == 0;
$clearpid = open3 ($clearin, $clearout, $clearout, $cleartool, "-status");
return (-1, ('Clearcase not installed')) unless $clearpid;
$clearpid = open3 ($clearin, $clearout, $clearout, $cleartool, "-status");
return (-1, ('Clearcase not installed')) unless $clearpid;
$self->{lastcmd} = 'cleartool ' . $cmd;
$self->{status} = $status;
$self->{output} = join "\n", @output;
$self->{lastcmd} = 'cleartool ' . $cmd;
$self->{status} = $status;
$self->{output} = join "\n", @output;
return ($status, @output);
} # execute
return ($status, @output);
} # execute
=cut
if (-f "$FindBin::Bin/shh") {
=cut
if (-f "$FindBin::Bin/shh") {
- $log->msg("Not speaking because we were asked to be quiet - $msg");
- verbose "Not speaking because we were asked to be quiet - $msg";
# TODO: Make it work on Windows...
return if $^O =~ /win/i;
# TODO: Make it work on Windows...
return if $^O =~ /win/i;
- open my $loadAvg, '/proc/loadavg'
+ open my $loadAvg, '<', '/proc/loadavg'
or croak "Unable to open /proc/loadavg\n";
my $load = <$loadAvg>;
or croak "Unable to open /proc/loadavg\n";
my $load = <$loadAvg>;