New: bash history emailing systemd.unit
This commit is contained in:
parent
357eef8ec9
commit
a84e5015b6
9
systemd/system/bash_eternal_email.service
Normal file
9
systemd/system/bash_eternal_email.service
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Emailing bash history
|
||||||
|
Wants=bash_eternal_email.timer
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=root
|
||||||
|
Group=root
|
||||||
|
Type=oneshot
|
||||||
|
ExecStart=/usr/local/bin/bash_eternal_email.sh
|
11
systemd/system/bash_eternal_email.timer
Normal file
11
systemd/system/bash_eternal_email.timer
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Emailing bash history
|
||||||
|
Requires=bash_eternal_email.service
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
Unit=bash_eternal_email.service
|
||||||
|
OnCalendar=Fri *-*-* 22:00:00
|
||||||
|
RandomizedDelaySec=30min
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
42
systemd/system/timer-scripts/template.bash_eternal_email.sh
Executable file
42
systemd/system/timer-scripts/template.bash_eternal_email.sh
Executable file
|
@ -0,0 +1,42 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Sends an encrypted email attachment of the bash eternal history directory
|
||||||
|
|
||||||
|
declare -r backup_p=/home/emiliko/safe/bash_eternal_backups
|
||||||
|
declare -r email_msg="$(mktemp)"
|
||||||
|
declare -r encry_file="$(mktemp)"
|
||||||
|
chmod 666 "$encry_file"
|
||||||
|
|
||||||
|
sudo -u emiliko bash <<CMD
|
||||||
|
cd "${backup_p}/.." || exit 1
|
||||||
|
tar czf - "$(basename "$backup_p")" | gpg -e -r emiliko@mami2.moe > "$encry_file"
|
||||||
|
CMD
|
||||||
|
|
||||||
|
declare -r MIMEType="$(file --mime-type "$encry_file" | sed 's/.*: //')"
|
||||||
|
declare -r attach_name="bash_full_backup_$(date +%s).tgz"
|
||||||
|
|
||||||
|
cat <<EMAIL >"$email_msg"
|
||||||
|
Dear Emiliko,
|
||||||
|
|
||||||
|
I thought you might like a backup of your .bash_eternal_history files from all
|
||||||
|
devices I can access. I used $(hostname) as a central repository to back them
|
||||||
|
up. Hope you enjoy them!
|
||||||
|
|
||||||
|
yours (truly),
|
||||||
|
Systemd
|
||||||
|
EMAIL
|
||||||
|
|
||||||
|
curl --silent --ssl-reqd \
|
||||||
|
--url 'smtps://smtp.fastmail.com:465' \
|
||||||
|
--user 'emiliko%40mami2.moe:<password-here>' \
|
||||||
|
--mail-from "systemd@mami2.moe" \
|
||||||
|
--mail-rcpt 'emiliko@cs.ox.ac.uk' \
|
||||||
|
--mail-rcpt 'emiliko@mami2.moe' \
|
||||||
|
-F '=(;type=multipart/mixed' \
|
||||||
|
-F "=$(cat "$email_msg");type=text/plain" \
|
||||||
|
-F "file=@${encry_file};type=${MIMEType};encoder=base64" \
|
||||||
|
-F '=)' \
|
||||||
|
-H "From: Systemd-chan <systemd@mami2.moe>" \
|
||||||
|
-H "Subject: Your weekly bash backup" \
|
||||||
|
-H "To: Emiliko Mirror <emiliko@cs.ox.ac.uk>" \
|
||||||
|
-H "CC: Emiliko Mirror <emiliko@mami2.moe>" \
|
||||||
|
-H "Date: $(date)"
|
Loading…
Reference in a new issue