Skip to content

Instantly share code, notes, and snippets.

@EnigmaCurry
Last active April 26, 2022 05:32
Show Gist options
  • Save EnigmaCurry/76128601521d7e9762063b48f4f7d789 to your computer and use it in GitHub Desktop.
Save EnigmaCurry/76128601521d7e9762063b48f4f7d789 to your computer and use it in GitHub Desktop.
cpu_keepalive

cpu_keepalive

For some reason my computer locks up if it goes idle. This script will install a systemd timer to keep it alive, by performing a small calculation every minute.

Copy and paste this entire script into your BASH shell, including the starting and ending parentheses:

( set -e
# Install systemd unit in regular user account:
mkdir -p ~/.config/systemd/user

cat <<EOF > ~/.config/systemd/user/cpu_keepalive.timer
[Unit]
Description=cpu_keepalive.timer

[Timer]
OnCalendar=*-*-* *:*:00
Persistent=true

[Install]
WantedBy=timers.target
EOF

cat <<EOF > ~/.config/systemd/user/cpu_keepalive.service
[Unit]
Description=cpu_keepalive.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "dd if=/dev/urandom bs=5M count=1  2>&1 | bzip2 | base64 > /dev/null"
KillSignal=SIGKILL
EOF

systemctl --user daemon-reload
systemctl --user enable --now cpu_keepalive.timer
systemctl --user --no-pager status cpu_keepalive
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment