
scripts for Synology DSM
How do I run scripts from Synology Task Scheduler and how do I create scripts?
Click here for instructions how to create scripts and run those scripts from the Synology Task Scheduler in Control Panel.
Warning
Warning: always test scripts in a testing environment before usage, use at your own risk
This version: Simulate deleting empty directories & empty directories with only @eaDir directory
- Does not delete anything
- Only logs what would be deleted
- Lets you safely review results
What You’ll Get:
- A log file named cleanup_simulation_log.txt will be created
- You can inspect it to see exactly which folders would be deleted, without any risk
Script:
#!/bin/bash
# Set your shared folder path
START_DIR=”/volume1/Shared Folder With Spaces”
# Set log file path
LOG_FILE=”/volume1/Shared Folder With Spaces/cleanup_simulation_log.txt”
echo “=== Cleanup Simulation Run: $(date) ===” >> “$LOG_FILE”
# Simulate: Find empty directories
find “$START_DIR” -type d -empty | while IFS= read -r dir; do
echo “[SIMULATION] Would delete empty directory: $dir” >> “$LOG_FILE”
done
# Simulate: Find directories that only contain @eaDir
find “$START_DIR” -type d ! -empty | while IFS= read -r dir; do
children=()
while IFS= read -r entry; do
children+=(“$entry”)
done < <(find “$dir” -mindepth 1 -maxdepth 1)
if [ “${#children[@]}” -eq 1 ] && [[ “$(basename “${children[0]}”)” == “@eaDir” ]]; then
echo “[SIMULATION] Would delete directory with only @eaDir: $dir” >> “$LOG_FILE”
fi
done
echo “=== Simulation complete ===” >> “$LOG_FILE”
echo >> “$LOG_FILE”
Warning
Warning: always test scripts in a testing environment before usage, use at your own risk
This version: Deleting empty directories & empty directories with only @eaDir directory
Deletes only safe targets (empty folders or
@eaDir
-only)Logs everything to a file for your review
What You’ll Get:
- A log file named cleanup_log.txt will be created
Script:
#!/bin/bash
# Set your shared folder path
START_DIR=”/volume1/Shared Folder With Spaces”
# Set log file path (must be writable by the user running the task)
LOG_FILE=”/volume1/Shared Folder With Spaces/cleanup_log.txt”
echo “=== Cleanup run: $(date) ===” >> “$LOG_FILE”
# Find and delete empty directories
find “$START_DIR” -type d -empty | while IFS= read -r dir; do
echo “Deleting empty directory: $dir” >> “$LOG_FILE”
rm -r “$dir”
done
# Find and delete directories that only contain @eaDir
find “$START_DIR” -type d ! -empty | while IFS= read -r dir; do
children=()
while IFS= read -r entry; do
children+=(“$entry”)
done < <(find “$dir” -mindepth 1 -maxdepth 1)
if [ “${#children[@]}” -eq 1 ] && [[ “$(basename “${children[0]}”)” == “@eaDir” ]]; then
echo “Deleting directory with only @eaDir: $dir” >> “$LOG_FILE”
rm -r “$dir”
fi
done
echo “=== Cleanup complete ===” >> “$LOG_FILE”
echo >> “$LOG_FILE”