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