Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

Commit a367c77

Browse files
authored
Merge pull request #9 from UNHCSC/8-feat-add-teleport-automation-scripts
feat: add automation scripts for teleport (#8)
2 parents 693ae68 + cfa1392 commit a367c77

5 files changed

Lines changed: 128 additions & 0 deletions

File tree

linux/cronjobs.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# cronjobs.sh - List all cronjobs on a system
4+
#
5+
# Usage:
6+
# ./cronjobs.sh
7+
#
8+
# Description:
9+
# This script lists all cron jobs for all users and system-wide cron jobs.
10+
#
11+
# Author: Dan McCarthy
12+
# Date: 3/13/2026
13+
14+
# ===
15+
# Output cronjobs for an associated user.
16+
#
17+
# Parameters:
18+
# User to check cronjobs
19+
# ===
20+
function list_crontab() {
21+
echo -e "\n=== Crontab jobs for $1 ==="
22+
crontab -l -u "$1" 2>/dev/null
23+
}
24+
25+
# === List Cron Jobs from Crontab for All Users ===
26+
echo -e "\n=== Listing Cron Jobs from Crontab for All Users ==="
27+
for user in $(getent passwd | cut -d: -f1); do
28+
list_crontab "$user"
29+
done
30+
31+
# === List System Cron Jobs from cron.d, cron.daily, cron.weekly, cron.monthly ===
32+
echo -e "\n=== Jobs from /etc/cron.d/ ==="
33+
cat /etc/cron.d/* 2>/dev/null
34+
35+
echo -e "\n=== Jobs from /etc/cron.daily/ ==="
36+
for f in /etc/cron.daily/*; do
37+
[ -f "$f" ] && echo "cron.daily: $f"
38+
done
39+
40+
echo -e "\n=== Jobs from /etc/cron.weekly/ ==="
41+
for f in /etc/cron.weekly/*; do
42+
[ -f "$f" ] && echo "cron.weekly: $f"
43+
done
44+
45+
echo -e "\n=== Jobs from /etc/cron.monthly/ ==="
46+
for f in /etc/cron.monthly/*; do
47+
[ -f "$f" ] && echo "cron.monthly: $f"
48+
done
49+
50+
echo -e "\n=== User cron jobs from /var/spool/cron/crontabs ==="
51+
if [ -d /var/spool/cron/crontabs ]; then
52+
for file in /var/spool/cron/crontabs/*; do
53+
user=$(basename "$file")
54+
echo "Cron jobs for user: $user"
55+
cat "$file" 2>/dev/null
56+
done
57+
fi

linux/placeholder.sh

Whitespace-only changes.

linux/teleport/backup.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
#
3+
# backup.sh - Backup teleport configuration
4+
#
5+
# Usage:
6+
# backup.sh <user>@<ip>
7+
#
8+
# Description:
9+
# This will create a backup of a locally installed teleport service. It
10+
# creates a 'teleport-backup_<time>.tar.gz' file with all of the imporant
11+
# directories used by teleport. These can then be reloaded using ./load_backup.sh.
12+
#
13+
# Author: Dan McCarthy
14+
# Date: 3/3/2026
15+
16+
# check that ssh destination is provided
17+
if [[ $# -ne 1 ]]; then
18+
echo "Please provide argument: './backup.sh <user>@<ip>'"
19+
exit 1
20+
fi
21+
22+
TARGET="$1"
23+
BACKUP_NAME="teleport-backup_$(date +%s).tar.gz"
24+
25+
# === Read password and backup files locally ===
26+
read -p "Enter Password: " PASSWORD
27+
sshpass -p "$PASSWORD" ssh "$TARGET" "sudo tar czpf ~/$BACKUP_NAME /etc/teleport.yaml /var/lib/teleport /opt/teleport"
28+
29+
# === Copy backup to system ===
30+
echo "This will take a second..."
31+
sshpass -p "$PASSWORD" scp "$TARGET:~/$BACKUP_NAME" .

linux/teleport/load_backup.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
#
3+
# load_backup.sh - Load teleport backup to system
4+
#
5+
# Usage:
6+
# load_backup.sh <backup> <user>@<ip>
7+
#
8+
# Description:
9+
# This program takes a backup generated by ./backup.sh and load
10+
# it on to a system with teleport.
11+
#
12+
# Author: Dan McCarthy
13+
# Date: 3/13/2026
14+
15+
# check that ssh destination is provided
16+
if [[ $# -ne 2 ]]; then
17+
echo "Please provide argument: './load_backup.sh <backup> <user>@<ip>'"
18+
exit 1
19+
fi
20+
21+
BACKUP="$1"
22+
TARGET="$2"
23+
24+
# === Copy local backup to system ===
25+
read -p "Enter Password: " PASSWORD
26+
27+
echo "Sending backup to system..."
28+
sshpass -p "$PASSWORD" scp $BACKUP "$TARGET:/tmp"
29+
30+
# === Extract backup ===
31+
echo "Extracting backups on system..."
32+
sshpass -p "$PASSWORD" ssh "$TARGET" sudo bash -s <<EOF
33+
34+
systemctl stop teleport
35+
36+
tar xzpf /tmp/$BACKUP -C / --same-owner
37+
38+
systemctl start teleport
39+
40+
EOF

windows/placeholder.ps1

Whitespace-only changes.

0 commit comments

Comments
 (0)