The officially official Devuan Forum!

You are not logged in.

#26 2018-05-02 00:38:21

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

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

Okay, one thing I just realized in looking at the anacrontab file in /etc. There is the following line:

1    5    cron.daily    run-parts --report /etc/cron.daily

I had previously put the script trim in /etc/cron.daily (and it's still there) so does that mean that trim ran?

Last edited by Ron (2018-05-02 00:38:56)

Offline

#27 2018-05-02 00:45:56

siva
Member
Registered: 2018-01-25
Posts: 276  

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

Here are some follow-up questions for you to consider:

How can you check if your script is in cron.daily?
What is the syntax for anacrontab?
How can you determine if anacron is running scripts?
How can you determine if anacron has ran your script?

If you can answer these, you'll probably be able to figure out your question.
Best of luck.

Offline

#28 2018-05-02 00:47:02

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

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

Now you're cooking.

cron.daily is a separate job. Yours is called example.daily and you are correct: You don't see it in syslog because you need to re-add it to /etc/anacrontab. The name of the job can be anything you want, by the way, so feel free to give it a more descriptive name such as automatic.trim or the like.

You can do it either way, Ron. If you put the script in /etc/cron.daily/ then the script will be run as part of the cron.daily job which comes with anacron by default (take a look inside /etc/anacrontab and you'll see the cron.daily job listed there). I prefer to have my scripts be their own separate jobs, because then they get their own separate timestamp file in /var/spool/anacron/ and things are a bit more explicit.

Last edited by GNUser (2018-05-02 00:50:38)

Offline

#29 2018-05-02 00:56:34

siva
Member
Registered: 2018-01-25
Posts: 276  

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

GNUser wrote:

I prefer to have my scripts be their own separate jobs, because then they get their own separate timestamp file in /var/spool/anacron/ and things are a bit more explicit.

Wouldn't the --verbose flag achieve the same result?
https://man.cx/run-parts(8)

Scratch that, I see what you meant.

Last edited by siva (2018-05-02 01:03:57)

Offline

#30 2018-05-02 01:18:22

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

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

Okay, I think it's finally working in a way I can understand. First, I delete the trim file out of the /etc/cron.daily folder (and kept the one in my Documents folder). Then I went back to the anacron file in /etc and added this:

1 8    automatic.trim   /bin/bash /home/ron/Documents/trim

I changed 10 minutes to 8 and using your suggestion named it automatic.trim. Rebooted and ran sudo cat /var/log/syslog | grep anacron and got this on one line:

May  1 19:06:28 localhost anacron[1661]: Will run job `automatic.trim' in 8 min.

Finally, checked that the log file automatic.trim exists, opened it up and found this: 20180501.

So, can I finally consider this as SOLVED? smile

Offline

#31 2018-05-02 01:27:05

siva
Member
Registered: 2018-01-25
Posts: 276  

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

Looks like you've made your first cron job smile

Some final thoughts:
1. anacron should have its own service that can be managed with the "service" command.  Example: service anacron restart can be used in lieu of rebooting your entire system.  This is true of many services: service --status-all

2. I really want to know why your anacrontab doesn't read:
1 8    automatic.trim   /sbin/fstrim --all || true
Also, what's the rationale behind keeping the " || true" statement?

Offline

#32 2018-05-02 01:45:32

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

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

siva wrote:

2. I really want to know why your anacrontab doesn't read:
1 8    automatic.trim   /sbin/fstrim --all || true
Also, what's the rationale behind keeping the " || true" statement?

You mean I really don't even need the trim script file?

As for the || true, I have no idea. I kept the file exactly the same as it was in Mint. Also, thanks for the tip in #1, and your link in your previous post.

And before I forget, many thanks to both siva and GNUser. I'm getting closer to ditching Mint and going with Miyo full-time.

Last edited by Ron (2018-05-02 01:59:55)

Offline

#33 2018-05-02 03:03:50

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

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

Yes, you can mark it as solved. The timestamp in /var/spool/anacron/ is proof that the job ran smile

Now we're just making things more elegant and streamlined.

Ron wrote:

You mean I really don't even need the trim script file?

That's correct. For a simple one-liner task such as this, you don't need a script. I didn't want to point it out before--thinking it might be rewarding for you to get this working "your way"--but you can accomplish what you need by simply having this in /etc/anacrontab:

1 8    automatic.trim   /sbin/fstrim --all

(siva is right: the || true is not only superfluous, it can potentially be misleading. Without || true in there, if the fstrim command fails (not that it ever should) then the overall anacron job fails and if you investigate you'll be able to see that it failed. With || true in there, if the fstrim command fails then the true command runs, completes successfully (the true command always does nothing and completes sucessfully--that is what it does by design, which seems silly but is actually useful in several settings), and the overall anacron job completes successfully because the last command it ran completed successfully.)

Last edited by GNUser (2018-05-02 03:15:48)

Offline

#34 2018-05-02 18:03:52

siva
Member
Registered: 2018-01-25
Posts: 276  

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

GNUser wrote:

the || true is not only superfluous, it can potentially be misleading

wink
My guess is that Mint chains the output to some other command or logger, or as you said, to keep the anacron job going without pause, but at the cost of not knowing that your fstrim failed or why.  Couldn't say for sure, though.

@Ron: I'm glad you solved your task.  Linux has a lot of options and ways to approach problems.  It looks like you found one that works for your needs.  Never stop learning smile

Last edited by siva (2018-05-02 18:10:17)

Offline

#35 2018-05-02 23:57:53

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

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

Thanks guys. I marked as solved.

Offline

Board footer