Cron Job Script

I am fairly new to cron jobs but I have created a bash script to trim my SSDs every day.

Here is the script

#!/bin/bash
# This script runs the fstrim command once a day and trims all the mounted file systems that support TRIM.
# It also appends the output of the command to the /var/log/trim.log file, which you can use to monitor the trim operations.

sudo fstrim -v --all >> /var/log/trim.log

The error I get is Permission Denied /var/log/trim.log

I want to keep a log of the trim operation what am I doing wrong. The cron job works without the append to log file. Any ideas?

So immediately I want to ask, have you tried putting the file somewhere else and seeing if the job gives you the same error?

Also, does the file "trim.log" exist, or is the job supposed to create the file everytime it runs? Sorry, just trying to get a better idea of what's going on here.

I will try a different location. Trim log exists I created it with nano so the command line should append the output of trim to the log file.

Well it seems the script is correct, has to wait till 1AM for the daily cron job to run the script and the log file has been updated correctly. Cron runs as root which var/logs permissions are root.

1 Like

Just be aware that TRIM can lead to unrecoverable data. The best setup is to have an SSD for the system and apps but an HDD for Data - decent notebooks like my youngest's Asus has SSD for Windows and HDD for data. Not all notebooks have this option so best to invest in external HDD for Data.

This is only for the Zorin OS Partition. There is very little data on the PC and what there is is backed up to the cloud.

I only use cloud for sharing mainly. I prefer local external storage. If internet goes down for any reason, so does your data.

I have local external storage for my Windows machine with lots of data but the Zorin PC is basically a browser and that's it.

Anyone know what time the Daily Cron jobs run or a way to tell?

Found it

grep run-parts /etc/crontab
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

6.25AM

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.