The officially official Devuan Forum!

You are not logged in.

#1 2018-04-29 17:06:47

Ron
Member
Registered: 2018-04-22
Posts: 65

[Miyo] How to set daily trim job? [SOLVED]

I would like to set the script file fstrim to daily. In Mint I use this command: sudo mv -v /etc/cron.weekly/fstrim /etc/cron.daily
but this doesn't work in Miyo. How do I set this in Miyo? Can I just copy the fstrim file from Mint over to Miyo?

Last edited by Ron (2018-05-02 23:58:20)

Offline

#2 2018-04-29 21:04:22

MiyoLinux
Member
Registered: 2016-12-05
Posts: 550

Re: [Miyo] How to set daily trim job? [SOLVED]

Hi Ron.

First, let me say that I have no experience with SSDs, so I can't give you an adequate answer. Perhaps someone else can answer you more fully.

Second, as Devuan is based on Debian, I would recommend reading how it's handled in Debian...I'm reluctant to say if your Mint file will work or not. Here are a few links to hopefully help, and I apologize that I can't help more.

https://www.google.com/search?q=fstrim+Debian

https://blog.liw.fi/posts/2017/08/05/en … s_and_lvm/

https://manpages.debian.org/stretch/uti … .8.en.html

https://wiki.debian.org/SSDOptimization


I have been Devuanated, and my practice in the art of Devuanism shall continue until my Devuanization is complete. Until then, I will strive to continue in my understanding of Devuanchology, Devuanprocity, and Devuanivity.

Veni, vidi, vici vdevuaned. I came, I saw, I Devuaned. wink

Offline

#3 2018-04-29 22:25:32

golinux
Administrator
Registered: 2016-11-25
Posts: 947

Re: [Miyo] How to set daily trim job? [SOLVED]

As to Mint . . . it is NOT recommended to mix Devuan repos even with other Debian derivatives.  It could put you into a whole world of hurt.  If you do try that, backup first and check dependency versions against those available in Devuan.  Then cross your fingers and recite the appropriate incantations.

Offline

#4 2018-04-30 13:27:42

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

@Ron: to your original question, I'm curious what doesn't work.  Are you saying the file /etc/cron.weekly/fstrim doesn't exist?

It may be helpful to copy and paste the file /etc/cron.weekly/fstrim (from your mint system) into this conversation so we all know what actions it does and can provide further direction.  fstrim should be available outside of mint (part of the util-linux package), so I see little reason not to modify it for your needs.  Just make sure you read the documentation smile

http://man7.org/linux/man-pages/man8/fstrim.8.html

Last edited by siva (2018-04-30 13:33:10)

Offline

#5 2018-04-30 15:43:41

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

siva wrote:
@Ron: to your original question, I'm curious what doesn't work.  Are you saying the file /etc/cron.weekly/fstrim doesn't exist?

Yes.

siva wrote:
It may be helpful to copy and paste the file /etc/cron.weekly/fstrim (from your mint system) into this conversation . . .

How do I attach a file to this forum? I don't see a way. Here's the text of the file:

#!/bin/sh
# trim all mounted file systems which support it
/sbin/fstrim --all || true

Offline

#6 2018-04-30 16:15:31

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron wrote:
#!/bin/sh
# trim all mounted file systems which support it
/sbin/fstrim --all || true

I am assuming you understand what this command does and why.

Have you ran this command in devuan yet (not as a cron job, just a command)?  If not, understand that there is a slight opportunity for misbehavior; because the developer hasn't messed with SSDs, you will basically be playing the role of tester.

If all you want is to know how to set up the cron job, then figure out which cron application your version of Mint uses first.  In devuan, you can either...
a) learn the cron version and syntax that miyo uses and create a new job for your needs; or,
b) if you really want, and if it's in the devuan repos, use the version of cron that Mint ships.  Just try to understand that you may end up setting up more than anticipated if it's not a miyo default.

Last edited by siva (2018-04-30 16:16:55)

Offline

#7 2018-04-30 16:31:10

GNUser
Member
Registered: 2017-03-16
Posts: 317

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron, I have a laptop with a SSD. An anacron job trims the SSD for me periodically.

Unless your machine is on 24/7, I'd go with anacron. Install it, then for a daily trim add this line to /etc/anacrontab:

1 1 dailytrim /sbin/fstrim -av

The first '1' means the job should run daily. The second '1' tells anacron to run the job one minute after anacron itself runs. (By default, anacron runs every time you boot, every time you resume from suspend, and everyday at 7:30 am. No matter how many times anacron runs in a 24 hour period, it will only run your job daily--it keeps track of when the job last ran with a timestamp in /var/spool/anacron/.)

If you are on a laptop and want the job to run regardless of whether you are on AC or battery power, make sure to edit /etc/default/anacron accordingly and remove the executable bit from /usr/lib/pm-utils/power.d/anacron if that file exists on your machine (see this).

Last edited by GNUser (2018-04-30 20:01:44)

Offline

#8 2018-04-30 20:20:00

GNUser
Member
Registered: 2017-03-16
Posts: 317

Re: [Miyo] How to set daily trim job? [SOLVED]

Oh, sorry to complicate things but if you installed Devuan Ascii from a live image (e.g., a Miyo live image), you may have been hit with this issue.

To check, run this command: ls -l /usr/sbin/anacron

If /usr/sbin/anacron is a link to /bin/true, then you need to run these commands for anacron to work properly:

sudo apt-get purge live-config live-config-doc live-config-sysvinit
sudo dpkg-divert --remove /usr/sbin/anacron
sudo apt-get install --reinstall anacron

Incidentally, this issue may explain why jobs in /etc/cron.daily aren't working for you. If anacron is present on your system, then cron delegates the jobs in /etc/cron.daily to anacron. However, if you installed from a live image, anacron is disabled until you do the above.

Last edited by GNUser (2018-04-30 20:22:47)

Offline

#9 2018-04-30 20:30:35

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

siva wrote:
If all you want is to know how to set up the cron job, then figure out which cron application your version of Mint uses first.  In devuan, you can either...
a) learn the cron version and syntax that miyo uses and create a new job for your needs; or,
b) if you really want, and if it's in the devuan repos, use the version of cron that Mint ships.  Just try to understand that you may end up setting up more than anticipated if it's not a miyo default.

Here's what I found in Mint:

Package: cron Version: 3.0pl1-128ubuntu2
and
Package: anacron Version: 2.3-23

I'm assuming that by default Mint uses the Ubuntu cron.

siva wrote:
I am assuming you understand what this command does and why.

Just that it runs a trim job, whatever that is. Anything beyond that is gooblygook to me.

Last edited by Ron (2018-04-30 20:33:31)

Offline

#10 2018-04-30 20:46:38

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron wrote:

siva wrote:
I am assuming you understand what this command does and why.

Just that it runs a trim job, whatever that is. Anything beyond that is gooblygook to me.

Uh, you may want to read about that just in case something ever, well...goes horribly wrong.  SSDs can be fickle.

In any case, if the fstrim command runs as-expected in your system, it should be trivial to make a new entry using whichever cron you prefer on devuan/miyo. 

https://www.tecmint.com/cron-vs-anacron … -on-linux/

Offline

#11 2018-04-30 21:01:34

MiyoLinux
Member
Registered: 2016-12-05
Posts: 550

Re: [Miyo] How to set daily trim job? [SOLVED]

I just want to thank siva and GNUser for trying to help with this situation. It's much appreciated on my part. Thank you.


I have been Devuanated, and my practice in the art of Devuanism shall continue until my Devuanization is complete. Until then, I will strive to continue in my understanding of Devuanchology, Devuanprocity, and Devuanivity.

Veni, vidi, vici vdevuaned. I came, I saw, I Devuaned. wink

Offline

#12 2018-04-30 21:28:19

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

siva wrote:
Have you ran this command in devuan yet (not as a cron job, just a command)?

I tried two ways, but can't get it to run right. First I just doubled clicked the file but it didn't run, it just opened up in my text editor. Then I tried pasting the path to it in the terminal and got this:

bash: /home/ron/Desktop/trim: Permission denied

Then I added sudo before the path and got this:

sudo: bash:: command not found

I'm starting to feel a little dumb. sad

Last edited by Ron (2018-04-30 21:28:51)

Offline

#13 2018-04-30 21:34:04

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

Based on the output, it looks like you mislaunched the command.  Research how to launch a custom script in a linux shell.

Also, I have no idea why you didn't just run:

/sbin/fstrim --all || true

directly in a root shell.

Offline

#14 2018-04-30 22:02:33

golinux
Administrator
Registered: 2016-11-25
Posts: 947

Re: [Miyo] How to set daily trim job? [SOLVED]

@Ron . . . Not that it would make a difference but are you aware that sudo is not enabled by default in Devuan?  Either add it to sudoers or su + root pw to get root permissions

Offline

#15 2018-04-30 22:18:20

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

golinux wrote:
Not that it would make a difference but are you aware that sudo is not enabled by default in Devuan?

Maybe the Miyo guys enable it? I've never gotten an error message, I get a prompt for my password. Also I have used sudo to open read only files.

siva wrote:
Also, I have no idea why you didn't just run: /sbin/fstrim --all || true directly in a root shell.

I ran it in the terminal but got this:

fstrim: /: FITRIM ioctl failed: Operation not permitted

Then I added sudo in front of it, and after putting in my password there was a brief pause, then "ron@miyolinux:~$" came back. So does that mean it worked? I rebooted and all seems well (so far).

Also, I want to thank everyone for taking the time to help me out with this things. I appreciate it much. I'm determined to become "systemd free."

Offline

#16 2018-04-30 23:04:37

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron wrote:

Then I added sudo in front of it, and after putting in my password there was a brief pause, then "ron@miyolinux:~$" came back. So does that mean it worked? I rebooted and all seems well (so far).

http://www.linfo.org/sbin.html

/sbin is a standard subdirectory of the root directory in Linux and other Unix-like operating systems that contains executable...programs. They are mostly administrative tools, that should be made available only to the root (i.e., administrative) user.

Notice the directory where fstrim resides.
Some utilities, like ifconfig, will not be seen at all without root privileges (sudo or su).
https://www.sudo.ws/man/1.8.3/sudo.man.html

The "pause" you mentioned was most likely the program running.

Last edited by siva (2018-04-30 23:07:44)

Offline

#17 2018-05-01 17:32:01

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

So taking everything that has been said and done in this thread, I gather that I may place the trim script file in /etc/cron.daily and it will do its job?

Offline

#18 2018-05-01 18:01:09

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

The way you add commands will depend on whether or not you use cron or anacron.  Each application has rich usage, and may require restarting its own daemon.  I cannot say with certainty because it's been a long time since I've needed to add or modify a cron or anacron job.  (I've also never modified cron commands on a Mint system, so I have no idea if the "Mint way" follows a different approach.)  However, the links below should provide ample documentation, or at least direction, for task scheduling on Debian/Devuan/Miyo.

https://debian-administration.org/artic … _with_cron
https://wiki.debian.org/CronAnacronAtBatchSchedulers

To be clear, I'm leaving the documentation because I'm not sure what kind of system you're using; on a server, I only use cron, but I've heard other users swear by anacron on laptops or other systems that are routinely powered-off/suspended/hibernated.

Last edited by siva (2018-05-01 18:06:11)

Offline

#19 2018-05-01 20:44:44

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

Okay, I think I got a handle on this. I added the following line to /etc/anacrontab:

@daily    10    example.daily   /bin/bash /home/ron/Documents/trim

and made sure I copied the trim script into my Documents folder. Is that all there is to it? Once again, thanks for helping.

FTR, I'm just an average desktop user that regularly powers off (no hibernation/suspend).

EDIT: I just checked out the link in GNUser's post, and I don't have an anacron file in /usr/sbin, just a link. Does that mean anacron isn't working?

Last edited by Ron (2018-05-01 20:52:16)

Offline

#20 2018-05-01 21:28:11

GNUser
Member
Registered: 2017-03-16
Posts: 317

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron, we're getting warmer. Just a few tips:

1. @monthly is the only supported shortcut. @daily and @weekly are not supported. Use 1 and 7 for daily and weekly, respectively. In other words, this is what you want in /etc/anacrontab:

1 10    example.daily   /bin/bash /home/ron/Documents/trim

2. /usr/sbin/anacron should definitely be a real file. Please run these commands:

sudo apt-get purge live-config live-config-doc live-config-sysvinit anacron
sudo dpkg-divert --remove /usr/sbin/anacron
sudo apt-get install anacron

(If you don't have sudo, then run the command su without any arguments, enter your root password, then run the above commands without sudo.)
After you've done the above, check /usr/sbin/anacron again. It should be a real, executable file (not a link).

3. At that point you are ready to test to see if it is working. Reboot your computer then run this command:

sudo cat /var/log/syslog | grep anacron

If anacron is working, you should see a line saying that job 'example.daily' will run in 10 minutes.

4. To make sure that the job actually ran, wait over 10 minutes then examine the contents of the file /var/spool/anacron/example.daily. If your job actually ran, that file should exist and should contain a timestamp like '20180501'

5. When the job runs, it will do exactly what /home/ron/Documents/trim tells it to do, which may or may not be what you intend. Would you kindly share the contents of that file?

Last edited by GNUser (2018-05-01 21:35:58)

Offline

#21 2018-05-01 22:36:48

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

@Ron: never apologize for making an effort to develop your understanding of a topic.

Two ways you can verify if a program is installed.  Replace "program" with anacron:
A) which program
The which command will print the full path of your program.  If it isn't in your executables path, the output will be blank.  If you want to check which directories are in your path, run "echo $PATH".   Note that root has different folders in their path than normal users, including /sbin.
B) find / -iname *program*
This will take awhile, but if it is anywhere in your system, it should find it.  This works for any file or directory, by the way.  -iname will ignore case (uppercase or lowercase) differences.  The asterisks (*) is a bash wildcard; in this case, find will find any file or folder with the string "anacron".

There are many more ways, but I prefer these.

You may want to research cron.daily and the others.

To reiterate, I'm not sure why you're pointing cron to a script that runs a simple command.  I would use a script if there were a series of lines.

Yesterday, Gnuser linked to an interesting case regarding anacron.  I'm assuming you read it.  No idea if it applies to your situation.  In any case, reinstalling  or installing anacron is trivial.

Last edited by siva (2018-05-01 22:37:41)

Offline

#22 2018-05-02 00:06:15

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

GNUser wrote:
Would you kindly share the contents of that file?

#!/bin/sh
# trim all mounted file systems which support it
/sbin/fstrim --all || true

siva wrote:
A) which program
B) find / -iname *program*

which anacron returned nothing while almost every line from find / -iname anacron ended with Permission denied.

siva wrote:
To reiterate, I'm not sure why you're pointing cron to a script that runs a simple command.  I would use a script if there were a series of lines.

If I had to do it manually, I'd probably forget about it. smile One thing I'm wondering about, can I turn this script into an .sh file that will run when I click on it?

Offline

#23 2018-05-02 00:20:20

siva
Member
Registered: 2018-01-25
Posts: 99
Website

Re: [Miyo] How to set daily trim job? [SOLVED]

Your script is three lines.  The third line contains the actual command you want to run.  And the command you want to run is only one line.
The only case in which I could see this being launched as a script is one where you want to add or modify to this command.  However, it doesn't sound like you want to in this case.

Ron wrote:

Permission denied.

Linux has several ways of saying, "you need to access this as root."  We talked about /sbin already.  And there is more than one protected folder in your filesystem.

can I turn this script into an .sh file

File extensions don't matter in linux like they do in windows.  However, your script includes a crunchbang (#!) with the interpreter as line 1.  So, for most cases, you shouldn't need to launch it by first running /bin/bash.  However, your file manager may be fickle about how it launches, and I don't know which file manager miyo uses.

I think it would be helpful to research shell scripting.  Nothing beats independent research.  If you want to analyze some simple ones for reference, you can check out some that I made for my Linux systems:
https://github.com/souperdoupe/crunkbon … ls/scripts

EDIT: to support what GNUser said below, "which" will usually determine if you have a program installed; it's useful because sometimes developers will change the installation path for an app (a common practice between *nix and *bsd distributions).  In debian, an even easier way to check for an app is to simply "apt-get install" your program.  wink

Last edited by siva (2018-05-02 00:25:26)

Offline

#24 2018-05-02 00:20:24

GNUser
Member
Registered: 2017-03-16
Posts: 317

Re: [Miyo] How to set daily trim job? [SOLVED]

Ron wrote:

which anacron returned nothing while almost every line from find / -iname anacron ended with Permission denied.

Ron, anacron isn't even installed on your system. In my previous post I listed everything you need to do. Sorry but unless you try what I suggested I cannot help you further.

The script will do what you want it to.

Offline

#25 2018-05-02 00:28:51

Ron
Member
Registered: 2018-04-22
Posts: 65

Re: [Miyo] How to set daily trim job? [SOLVED]

I just finished all the steps you gave me. It appears to have worked but I have one question. When I ran sudo cat /var/log/syslog | grep anacron I got this:

May  1 18:09:38 localhost anacron[1659]: Anacron 2.3 started on 2018-05-01
May  1 18:09:38 localhost anacron[1659]: Will run job `cron.daily' in 5 min.
May  1 18:09:38 localhost anacron[1659]: Will run job `cron.weekly' in 10 min.
May  1 18:09:38 localhost anacron[1659]: Will run job `cron.monthly' in 15 min.
May  1 18:09:38 localhost anacron[1659]: Jobs will be executed sequentially

Any idea why it says the daily cron will run in 5 minutes when it's set for 10?

EDIT: I think I know what happened. After installing anacron, I should have went back to re-add the line
1 10    example.daily   /bin/bash /home/ron/Documents/trim. I'm going back to add it again and retry everything. It should work this time!

Last edited by Ron (2018-05-02 00:40:43)

Offline

Board footer