How to Set Up Auto Screenshot Daily on Xubuntu (EN)

Step-by-step guide to set up daily auto screenshots on Xubuntu.

Tags:
  • #Linux
  • #Automation
  • #Bash Script
Learning Path: Not Found | Category: Linux Tips

Table of Content

  1. Introduction
  2. Requirements
  3. Bash Script: Explanation and Workflow
  4. Implementation Steps
  5. Tips and Troubleshooting
  6. Conclusion

1. Introduction

Taking automatic screenshots daily can help monitor activity or save important screen views. This article explains the steps to set up auto screenshots on Xubuntu using a bash script that runs automatically each time you log in.


2. Requirements

Before starting, make sure you have:


3. Bash Script: Explanation and Workflow

Here is the bash script to take automatic screenshots every 60 seconds:

#!/bin/bash

# Root directory for storing screenshots
ROOT_DIR="/home/adb/Pictures/daily-screenshots"

# Lock file to prevent duplication
LOCK_FILE="/tmp/auto_screenshot.lock"

# Ensure only one instance is running
exec 200>"$LOCK_FILE"
flock -n 200 || exit 1

# Ensure the root storage directory exists
mkdir -p "$ROOT_DIR"

# Environment variables for graphical display
export DISPLAY=:0
export XDG_RUNTIME_DIR=/run/user/$(id -u)

# Log file
LOG_FILE="/home/adb/Pictures/screenshot_log.txt"

# Delete folders older than 7 days (executed once at login)
find "$ROOT_DIR" -mindepth 1 -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;

# Function to handle script termination
cleanup() {
  echo "Stopping auto_screenshot.sh" >> "$LOG_FILE"
  rm -f "$LOCK_FILE"  # Remove lock file
  exit 0
}

# Capture termination signals (SIGTERM, SIGINT)
trap cleanup SIGTERM SIGINT

# Infinite loop to take screenshots every 60 seconds
while true; do
  # Date for folder name (format: DD MMM YYYY)
  DATE_FOLDER=$(date "+%d %b %Y")
  OUTPUT_DIR="$ROOT_DIR/$DATE_FOLDER"

  # Ensure the date storage directory exists
  mkdir -p "$OUTPUT_DIR"

  # Screenshot file name format (example: 19 Jan 2025, 22:30.png)
  TIMESTAMP=$(date "+%d %b %Y, %H:%M")
  OUTPUT_FILE="$OUTPUT_DIR/$TIMESTAMP.png"
  
  # Take a screenshot
  xfce4-screenshooter -f -s "$OUTPUT_FILE" >> "$LOG_FILE" 2>&1
  
  # Wait 60 seconds before taking the next screenshot
  sleep 60
done

Workflow


4. Implementation Steps

1. Create the Bash Script

Open a terminal and create a new file:

nano ~/Pictures/auto_screenshot.sh

Copy and paste the script above into the file.
Save the file with CTRL + O, then exit with CTRL + X.

2. Grant Execution Permission

To make the script executable, change its permissions:

chmod +x ~/Pictures/auto_screenshot.sh

3. Add Script to Autostart Session

Use Xubuntu’s autostart session feature to run the script automatically at login:

  1. Open Settings Manager in Xubuntu.

  2. Go to Session and Startup > Application Autostart Tab.

  3. Click Add to create a new entry.

  4. Fill out the form as follows:

    • Name: Auto Screenshot
    • Command: /home/adb/Pictures/auto_screenshot.sh
    • Description: Script to take automatic screenshots every 60 seconds.
  5. Click OK to save changes.


5. Tips and Troubleshooting


6. Conclusion

With a bash script and autostart session configuration on Xubuntu, you can automatically take daily screenshots without manual intervention. This system is highly useful for documentation or monitoring computer activity.

Hope this guide is helpful! 🎉

Data Penggunaan Harian

TanggalUkuran File
19 Januari10 MB
20 Januari40 MB
21 Januari15 MB
22 Januari1 GB
Logo Adib

© 2025 Adib

GitHub