Script to run fstrim on root and log results to /var/log/trim.log in user-friendly meaner
#!/bin/bash
# Script to run fstrim on root and log results to /var/log/trim.log in user-friendly meaner
if [ -z "$1" ]
then
echo "ERROR: input parameter is missing! Mount point is expected."
echo -e "\tExample: .${0##*/} \"/\""
exit 2
fi
trimSize=$( fstrim $1 -v | cut -f 2 -d ' ')
trimSize=$((trimSize / (1024 * 1024)))
echo "fstrim: $1 $trimSize Mb were trimmed"
echo -e "$(date +'%x %X'):\t$1\t$trimSize Mb were trimmed" >> /var/log/trim.log
exit 0
#/etc/systemd/system/ftrim.service
[Unit]
Description=Run fstrim on startup
[Service]
Type=oneshot
ExecStart=/bin/sh -c "echo $(date -R): $(fstrim --all --verbose) >> /var/log/fstrim.log"
[Install]
WantedBy=multi-user.target