From 3e72fad53d5713d1bf413b39143e8edc6b990f50 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:14:11 -0700 Subject: [PATCH] New: systemd.timer for pushing bash history --- systemd/system/bash_eternal_push.service | 9 ++++ systemd/system/bash_eternal_push.timer | 11 +++++ .../template.bash_eternal_push.sh | 45 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 systemd/system/bash_eternal_push.service create mode 100644 systemd/system/bash_eternal_push.timer create mode 100755 systemd/system/timer-scripts/template.bash_eternal_push.sh diff --git a/systemd/system/bash_eternal_push.service b/systemd/system/bash_eternal_push.service new file mode 100644 index 0000000..c61bb16 --- /dev/null +++ b/systemd/system/bash_eternal_push.service @@ -0,0 +1,9 @@ +[Unit] +Description=Pushing bash history +Wants=bash_eternal_push.timer + +[Service] +User=root +Group=root +Type=oneshot +ExecStart=/usr/local/bin/bash_eternal_push.sh diff --git a/systemd/system/bash_eternal_push.timer b/systemd/system/bash_eternal_push.timer new file mode 100644 index 0000000..68304ba --- /dev/null +++ b/systemd/system/bash_eternal_push.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Pushing bash history +Requires=bash_eternal_push.service + +[Timer] +Unit=bash_eternal_push.service +OnCalendar=*-*-* *:00/30 +RandomizedDelaySec=30min + +[Install] +WantedBy=timers.target diff --git a/systemd/system/timer-scripts/template.bash_eternal_push.sh b/systemd/system/timer-scripts/template.bash_eternal_push.sh new file mode 100755 index 0000000..04536f8 --- /dev/null +++ b/systemd/system/timer-scripts/template.bash_eternal_push.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# Backup the .bash_eternal_history file of select users. Files should all be +# named in the format +# +# ${hostname}_${user}_bash_hist + +# Remote is being read out of ${remote_user}'s .ssh/config +# Do not leave a password on the ssh key! Use a restricted user instead + +declare -r remote=mirrorside +declare -r remote_user=emiliko +declare -r backup_p='/home/emiliko/safe/bash_eternal_backups' +declare -ar backups=(\ + /home/emiliko/.bash_eternal_history + "${backup_p}/waybook_emiliko_bash_hist" + /root/.bash_eternal_history + "${backup_p}/waybook_root_bash_hist" +) + +# Check for internet +if ! curl -m 3 archlinux.org &>/dev/null; then + echo "Failed to connect to archlinux.org in 3 seconds. No backup was made" >&2 + exit 1 +fi + +# Make the directory +sudo -u "$remote_user" bash <