Results 1 to 9 of 9

Thread: SSD Trim simple bash script program

  1. #1

    Default 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.

    Script:
    Code:
    #!/bin/bash
    xterm -hold -e fstrim -v /
    OS: openSUSE 11.4 x86_64
    Kernel: Linux 2.6.37.6-0.5-desktop
    Desktop: KDE 4.6.00 rel 6


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

  2. #2

    Default Re: SSD Trim simple bash script program

    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

  3. #3
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,724

    Default Re: SSD Trim simple bash script program

    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?
    Henk van Velden

  4. #4

    Default Re: SSD Trim simple bash script program

    Quote Originally Posted by Ecky View Post
    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
    True, I see that the OOTB cron scripts are there all as root.


    Ok thanks.

  5. #5

    Default Re: SSD Trim simple bash script program

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

    Thanks.

  6. #6

    Default Re: SSD Trim simple bash script program

    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:
    https://features.opensuse.org/312476

    SDB:SSD discard (trim) support - openSUSE

    Thank you everyone for the input!!

  7. #7

    Default Re: SSD Trim simple bash script program

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

    So it appears adding
    Code:
    ,discard
    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
    Code:
    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
    Code:
     /
    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.

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    24,724

    Default Re: SSD Trim simple bash script program

    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.
    Henk van Velden

  9. #9

    Default Re: SSD Trim simple bash script program

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

    I just tried to slip it in.........

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •