I'm really struggling to understand how logrotate
works when running a command within a shell file of my own, and how it doesn't.
The command in question is:
rclone -L -vv --log-file "/home/mike/tmp/qqq.log" sync "/media/mike/W10 D drive/My Documents/" remote:MyDocuments_M17A_from_Linux
What I would like:
I would like this qqq.log file to be checked quite often, say every 10 min., to see whether it has exceeded a given size, say 1 MB. And if it has, to rotate the file. rclone
with the -vv
option produces copious output, deliberately (i.e. to try to understand to get logrotate working for this use case).
There's a moderately helpful tutorial here, but it still leaves me in the dark:
-
How are you meant to configure rotation of logs from your own non-system processes? Are you meant to stick lines at the bottom of
/etc/logrotate.conf
? This is what I have done (under "#system-specific logs may be configured here"):/home/mike/tmp/qqq.log { notifempty size 1M daily create 0664 root root rotate 3 }
later: I now realise you can also put individual files in
/etc/logrotate.d
– no great complexity there. -
Is it the case that by default
logrotate
only runs once a day, by virtue of the file/etc/cron.daily/logrotate
? -
Does that mean that if I want much more frequent checking I should perhaps set up a
cron
job to do this, running (in this example) every 10 minutes? -
Are you meant to run
logrotate <config file>
as root? I ask this question because I have tried both as root and as user. User didn't seem to work.
A link to a beginner's guide to this sort of setup, which can't be that uncommon, would be helpful. I have searched but most of what I've found doesn't give you a step-by-step guide.
Best Answer
logrotate
can be run as an ordinary user, without administrative privileges, to rotate logs for that user.I've removed your
daily
criterion because you wanted purely a size-based check, and this would have limited any possible action to just once a day (the first time each day thatlogrotate
is run, as it happens). I've replacedcreate
withmissingok
so that it's up to your actualrclone
job to create the output file rather thanlogrotate
.Then put the
logrotate
command into your user'scrontab
file:Using this example, output from the command will be written to
.crontab.log
, and you'll probably want alogrotate
entry to cycle or reset it monthly.