|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Some Linux distributions, like Ubuntu MATE 18.04.2, do not enforce any trash limits. |
| 4 | +# Sending a file to the trash bin does not release disk space. |
| 5 | +# You would expect that the system automatically deletes old trashed files |
| 6 | +# as needed, but it just does not happen on some distributions. |
| 7 | +# |
| 8 | +# This script creates and trashes files in a loop, in order to stress |
| 9 | +# the trash bin and check whether your system enforces its trash limits. |
| 10 | +# |
| 11 | +# In the case of Ubuntu MATE 18.04.2, when the disk fills up, you do get |
| 12 | +# the following dialog box: |
| 13 | +# |
| 14 | +# This computer has only x,x GB disk space remaining. |
| 15 | +# |
| 16 | +# You can free up disk space by emptying the Trash, removing unused |
| 17 | +# programs or files, or moving files to an external disk. |
| 18 | +# |
| 19 | +# However, the stress script carries on and fills up the disk |
| 20 | +# until there are no free bytes left. That is actually an undesirable |
| 21 | +# situation, because full disks tend to cause trouble everywhere. |
| 22 | +# For example, choosing the "empty trash" option in the dialog box above |
| 23 | +# does not actually work, probably because the disk is full. |
| 24 | +# |
| 25 | +# This script uses tool 'trash', so remember to install package 'trash-cli' beforehand. |
| 26 | +# |
| 27 | +# Copyright (c) 2019 R. Diez - Licensed under the GNU AGPLv3 |
| 28 | + |
| 29 | +set -o errexit |
| 30 | +set -o nounset |
| 31 | +set -o pipefail |
| 32 | + |
| 33 | +# set -x # Enable tracing of this script. |
| 34 | + |
| 35 | +declare -r EXIT_CODE_ERROR=1 |
| 36 | + |
| 37 | +abort () |
| 38 | +{ |
| 39 | + echo >&2 && echo "Error in script \"$0\": $*" >&2 |
| 40 | + exit $EXIT_CODE_ERROR |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +# ------- Entry point ------- |
| 45 | + |
| 46 | +if (( $# != 0 )); then |
| 47 | + abort "Invalid number of command-line arguments." |
| 48 | +fi |
| 49 | + |
| 50 | +declare -r -i FILE_SIZE_KB=$(( 1 * 1024 * 1024 )) |
| 51 | + |
| 52 | +declare -i ITERATION_COUNTER=1 |
| 53 | + |
| 54 | +while true; do |
| 55 | + |
| 56 | + printf -v FILENAME "StressTrashTestFile-%06d.bin" "$ITERATION_COUNTER" |
| 57 | + |
| 58 | + echo "Creating and deleting file $FILENAME ..." |
| 59 | + |
| 60 | + dd bs=1024 count="$FILE_SIZE_KB" if=/dev/urandom of="$FILENAME" status="none" |
| 61 | + |
| 62 | + trash "$FILENAME" |
| 63 | + |
| 64 | + ITERATION_COUNTER=$(( ITERATION_COUNTER + 1 )) |
| 65 | + |
| 66 | +done |
0 commit comments