SSD Trim simple bash script program

Hi folks, I wrote this script which works but it should run automatically about once per week.

I hunted and experimented with KDE Task Scheduler (no dice and no help anywhere) and cron (confusing instructions and cannot edit crontab -e with vim, and cannot enter cron folders/files).

I would settle for a desktop shortcut to run the script but found no help for that.


xterm -hold -e fstrim -v /

OS: openSUSE 11.4 x86_64
Kernel: Linux
Desktop: KDE 4.6.00 rel 6

I am not asking anyone to write code, I could use some pointers, though.

Try placing your script in /etc/cron.weekly

You need to be root to do this and you can do it with a command like this:

sudo cp /path/to/your/script/scriptname /etc/cron.weekly/scriptname

To edit anything cron you have to be root, I often use kwrite for this kinda thing by doing Alt & F2, kdesu kwrite

As @Ecky tells you, puting it there will let it be run as root.

When this should not run as *root, *you should use the users crontab.

But I have doubts about this running in an *xterm. *Things run by cron are batch runs. Thus thre is no X screen connected to them. And as xterm is an X program, this will be a problem. Why not just run he program?

True, I see that the OOTB cron scripts are there all as root.

Ok thanks.

True, I just wanted to be notified when it happened. However, there are other ways to determine if it is working.


I wound up modifying the fstab so trim would occur on every cold boot and restart. It would be easier to view this thread I started in Linux Questions:SSD Trim simple bash script program But I backed up the drive image with Image for Linux and when attempting to restore, the last image I made showed 0 bytes and asked for the media even though it and all images are kept on a second drive. I have to do more testing to find out if the fstab mods caused this. Otherwise, it may be cron.

Other SUSE literature on the subject:

SDB:SSD discard (trim) support - openSUSE

Thank you everyone for the input!!

The backup image failure was a fluke (the disk is a little beat up).

So it appears adding


to fastab mount options is a workable way to go.

If an application would benefit from more frequent trims, then cron is the way to go.

One question, however. The script command I have is

xterm -hold -e fstrim -v /

. Obviously the -v should go as well as the call for x-term in my original script. But will just the


argument trim all the partitions?

There are two in fstab (disregarding swap, which should researched further).

In fact, the question which partition needs trimming has not been definitively answered AFAIK.

In fact, the question which partition needs trimming has not been definitively answered AFAIK.

You did not ask for any advise about the fstrim tool. You asked for advise about

it should run automatically about once per week.

and then you added some vague statements about strange things you tried using cron.

Thus an advise was given how to run a statement once a week as root (and that statement can of course be a call of a much larger script.

Thus I guess your question was answered.

When you want advise on the usage of fstrim (after reading the it’s man page), you better make a new thread with at least the word “fstrim” in the title to lure fstrim gurus into helping you.

True, I need to research man fstrim + mount (8) and start a new thread.

I just tried to slip it in…:slight_smile: