a python dead man switch script
git clone git://
Log | Files | Refs | README | LICENSE

commit 89af1a6c5a7b8ebd26e33838961af28f443783b8
Author: tx <>
Date:   Sun, 20 Aug 2017 02:13:01 +0200

init commit

LICENSE | 21+++++++++++++++++++++
README | 23+++++++++++++++++++++++ | 33+++++++++++++++++++++++++++++++++
requirements.txt | 1+
4 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 tx <> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README b/README @@ -0,0 +1,23 @@ +dms - a python dead man switch script + +it is meant to be run on a personal remote server that you login to frequently + +since it uses your last login time, once configured and croned, you can forget +about it and go on with your life, no need to manually reset the switch. + +if you did login during the last X days, dms will exit with 1, this avoids an +accidental trigger in case or error with the script + +dms will exit with 0 if you didn't login for `delay_days` days. + +# requirements + +requires python-utmp library + +# configuration + +modify `user` and `delay_days` variables located at the top of the script + +# usage example + +cron everyday: ` && rm -rf ~/porn &&` diff --git a/ b/ @@ -0,0 +1,33 @@ +#!/usr/bin/env python +import utmp +from sys import stderr +from datetime import datetime, timedelta + +user = 'yourlogin' +delay_days = 20 + +def trigger(): + stderr.write('You are dead\n') + exit(0) + +# read wtmp database +with open('/var/log/wtmp', 'rb') as fd: + buf = +entries = list( + +# iterate until we find last remote login of user +last = entries.pop() +while len(entries) > 0 and last.user != user: + last = entries.pop() + +# no login found +if last.user != user: + trigger() + +# check last login +if - last.time > timedelta(days = delay_days): + trigger() + +# thou are not dead, exit with 1 (a bug would lead to the same result) +print('last login: {}'.format(last.time)) +exit(1) diff --git a/requirements.txt b/requirements.txt @@ -0,0 +1 @@ +utmp