Batched-trim.sh

Aus Linupedia.org
Wechseln zu: Navigation, Suche

Das ist eigentlich eher ein bash script. Oder mix. Zielsetzung ist dieses Script einmal wöchentlich durch cron ausführen zu lassen. Es ist als Ersatz für Konfigurationen gedacht, bei denen vom Betriebssystem mitgelieferte Funktionen nicht greifen können. Außerdem wurde ein Anbindung an das journal von "systemd" gewünscht.

Zur Entstehung siehe bitte: http://linux-club.de/forum/viewtopic.php?f=91&t=120539

Features:

  • Loganbindung für systemd journal durch 'logger'.
  • Zu trimmende Pfade können definiert werden.
  • Benachrichtigt Desktopbenutzer mithilfe "wall".
  • Wöchentlich automatisiert durch cron.

Pfad: Zur einmalig wöchentlichen Ausführung wird er hier als ausführbar abgelegt:

/etc/cron.d/cron.weekly/ext4-strim.sh

Inhalt:

#!/bin/sh
### Trim script for SSD |ext4-trim.sh| ###
# - sends a message whats going on to logged in users with wall
# - Logs trim output to journal
# Space separated list of filesystems to trim:
FS="/ /home";
# message for desktop users: (not logged)
TEXT="Starting batched trim!";
# Setup logger with identifier:
log="logger -t ext4-trim.sh";
# Send message:
wall -n $TEXT;
# Execute the trim command and log to journal:
echo "*** $TEXT ***" | $log;
 for i in $FS; do
  /usr/sbin/fstrim -v "$i" | $log;
 done;
exit 0;