Skip to content

Instantly share code, notes, and snippets.

@Ciantic
Last active October 28, 2025 08:27
Show Gist options
  • Select an option

  • Save Ciantic/66b583ee8b57d4cb56963ae98c3d9f6d to your computer and use it in GitHub Desktop.

Select an option

Save Ciantic/66b583ee8b57d4cb56963ae98c3d9f6d to your computer and use it in GitHub Desktop.
Suspend from tty script
#!/bin/bash
# Gnome-shell+Nvidia sometimes fails to suspend, os instead change to tty3 and suspend from there, then return to tty2.
set -e
# Current wakeup count
WAKEUPS=$(cat /sys/power/wakeup_count)
# switch to TTY3 and suspend
echo "Switching to TTY3 and suspending..."
chvt 3
sleep 1
systemctl suspend
sleep 1
# Wait until resumed
while [ "$(cat /sys/power/wakeup_count)" -eq "$WAKEUPS" ]; do
echo "System is suspended... waiting to resume."
sleep 1
done
echo "Resumed from suspend, switching to TTY2."
# switch back to TTY2
chvt 2
# Get last wakeup moment?
# stat /sys/power/wakeup_count
# File: /sys/power/wakeup_count
# Size: 4096 Blocks: 0 IO Block: 4096 regular file
# Device: 0,25 Inode: 1310 Links: 1
# Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
# Context: system_u:object_r:sysfs_t:s0
# Access: 2025-10-27 23:40:13.625259807 +0200
# Modify: 2025-10-27 23:40:13.625259807 +0200
# Change: 2025-10-27 23:40:13.625259807 +0200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment