Last active
October 23, 2021 16:19
-
-
Save hydrastro/529238468f4cc697852e6af5d2042a5b to your computer and use it in GitHub Desktop.
dead_switch.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Add this script to crontab: | |
| # `sudo printf "33 3\t* * *\troot\t/etc/dead_switch.sh" >> /etc/crontab` | |
| # Dead Switch configuration | |
| your_email="" | |
| server_username="" | |
| warning_time=$((3600 * 24 * 14)) | |
| trigger_time=$((3600 * 24 * 28)) | |
| # Emails | |
| warning_email_title="[WARNING] Dead Switch" | |
| warning_email_body="Server feels alone, please log in." | |
| critical_email_title="[CRITICAL] Dead Swtich" | |
| critical_email_body=$(cat <<EOF | |
| Log in immediately. | |
| The dead switch will be triggered within 24 hours. | |
| EOF | |
| ) | |
| farewell_email_title="Farewell" | |
| farewell_email_body="It's been nice." | |
| last_login_time=$(last -1 -R "$server_username" --time-format iso | \ | |
| awk '{print $3}' | date -d "$1" +"%s") | |
| current_time=$(date +%s) | |
| if [[ $current_time -gt $((last_login_time + warning_time)) ]]; then | |
| send_mail "$your_email" "$warning_email_title" "$warning_email_body" | |
| fi | |
| if [[ $current_time -gt $((last_login_time + trigger_time - 86400)) ]]; then | |
| send_mail "$your_email" "$critical_email_title" "$critical_email_body" | |
| fi | |
| if [[ $current_time -gt $((last_login_time + trigger_time)) ]]; then | |
| send_mail "$your_email" "$farewell_email_title" "$farewell_email_body" | |
| # Here you do your stuff. Example: | |
| # send_mail "[email protected]" "[IMPORTANT] Dead Switch" \ | |
| # "Anon is dead.\nHis last words: good luck lmao." | |
| # srm -rf / | |
| sed -i '/dead_switch/s/^/#/g' /etc/crontab | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
send_mailis defined here: https://gist.github.com/hydrastro/5ccfc0dc87a8bb3c5ec9062a3cba5bf6sed -i '/dead_switch/s/^/#/g' /etc/crontabcomments out the crontab entry for the dead switch, so it doesn't run twice.