From: Christian Heller Date: Thu, 24 Dec 2015 14:39:07 +0000 (+0100) Subject: Initial add of files of current work state. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/%7Broute%7D?a=commitdiff_plain;h=1b3fa2e791597ba751b18fb321b4fe918aa98cbb;p=pingmail.git Initial add of files of current work state. --- diff --git a/README b/README new file mode 100644 index 0000000..dfe8255 --- /dev/null +++ b/README @@ -0,0 +1,21 @@ +Small shell script to regularly check a target person's responsiveness via mail. + +Expects mutt to be usable for sending mails via command line. + +When run as "pingmail check", searches a maildir for the most recent file +matching a regex pattern (such as a "From: " field matching the target person), +and if the most recent file is too old, sends an e-mail to the target person +requesting some sign of life. After some more wait time without a sign of life, +sends a warning message to another mail address that target person is +unresponsive. + +The wait time counter can be reset manually with "pingmail touch". + +The wait time, the target and checking persons' mail addresses, the regex, the +maildir path etc. must be set in a dotfile ~/.pingmailrc. See comments in +pingmailrc.example file for more details. + +To install as an hourly cronjob, define $path_to_pingmail_script_file, then do: + +line='0 * * * * '$path_to_pingmail_script_file' check' +(crontab -l; echo $line) | crontab - diff --git a/README.md b/README.md deleted file mode 100644 index 2875ae8..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# pingmail -regularly check target person's responsiveness by mail diff --git a/pingmail b/pingmail new file mode 100755 index 0000000..4724412 --- /dev/null +++ b/pingmail @@ -0,0 +1,87 @@ +#!/bin/sh + +set -e + +# read in dotfile +pingmailrc=$HOME'/.pingmailrc' +if [ ! -f $pingmailrc ]; then + echo 'No .pingmailrc found at '$pingmailrc', aborting.' + exit +fi +. $HOME'/.pingmailrc' +mkdir -p $testdir + +# interpret arguments +if [ "$1" = "check" ]; then + continue +elif [ "$1" = "touch" ]; then + touch $ping_touch + exit +else + echo 'usage: '$0' COMMAND\n(COMMAND one of "check", "touch")' + exit +fi + +# check test file for last modtime +modtime_pingfile=0 +if [ -f $ping_touch ]; then + modtime_pingfile=`stat $ping_touch --format=%Y` +fi + +# search maildir for last life sign datetime +modtime_mails=0 +while read file; do + if [ -z $file ]; then + break + fi + modtime=`stat $file --format=%Y` + if [ "$modtime" -gt "$modtime_mails" ]; then + modtime_mails=$modtime + fi +done < wait time, send reminder to person to check with, start reminder +# mail timer if not in existence, re-touch ping wait file +if [ "$delta" -gt "$wait_time" ]; then + echo $msg2checked | mutt -s "$subj2checked" $checked_address + echo "Sending ping message." + touch $ping_touch + if [ ! -f "$reminder_touch" ]; then + touch $reminder_touch + echo "Creating reminder message wait time file." + fi +fi + +# if last life sign datetime / test file modtime > modtime of reminder touch +# file, delete it; otherwise, if delta between those > wait time, send reminder +# to person checking and then delete reminder touch file +if [ -f "$reminder_touch" ]; then + modtime_reminder=`stat $reminder_touch --format=%Y` + if [ "$modtime" -gt "$modtime_reminder" ]; then + rm $reminder_touch + echo "Deleting reminder message wait time file." + else + delta=`expr $now - $modtime_reminder` + if [ "$delta" -gt "$wait_time" ]; then + echo $msg2checker | mutt -s "$subj2checker" $checker_address + echo "Sending reminder message." + rm $reminder_touch + echo "Deleting reminder message wait time file." + fi + fi +fi diff --git a/pingmailrc.example b/pingmailrc.example new file mode 100644 index 0000000..6ac22bd --- /dev/null +++ b/pingmailrc.example @@ -0,0 +1,39 @@ +# place for test files whose modification times are used to track lifesigns +testdir=$HOME'/.pingmail' + +# modification time is the last time a ping was sent or a lifetime received +ping_touch=$testdir'/ping_touch' + +# modification time is when the count for sending checker a warning mail starts +reminder_touch=$testdir'/reminder_touch' + +# to recursively search for most recent matches to $matchstring as lifesigns +maildir=$HOME'/mail' + +# how long to wait for lifesigns before sending a ping; double is time to wait +# for a lifesign before sending a warning message to checker +wait_time=86400 + +# address of the checker, receives warning message after too long wait +checker_address='bar@example.org' + +# address of the checked person, ping is sent here +checked_address='foo@example.org' + +# content of ping message sent to checked person +subj2checked='[pingmail] Ping!' +msg2checked='Hi!\n +\nThis is an automated mail ping from '$checker_address'. +\nRespond to show that you are still alive!' + +# content of warning message sent to checker +id_target='foo' +subj2checker='[pingmail] No recent life signs from '$id_target +reminder_time=`expr $wait_time \* 2` +msg2checker='pingmail reporting in:\n +\nNo life signs from '$id_target' for the last '$reminder_time' seconds. +\nMaybe you should give them a call to check if they are okay.' + +# pattern to search $maildir for recursively for lifesigns +checked_address_escaped=`echo $checked_address | sed 's/\./\\./g'` +matchstring='^From: .*('$checked_address_escaped'|alternate@example\.org)'