Score:1

crontab not deleting files

cf flag

I have crontab commands on Ubuntu 20.04, that looks like this :

* * * * * /usr/bin/find /backup-nfs/ -name "*.sql" -path "/backup-nfs/*.sql" -type f -mtime +1 -delete
* * * * * find /backup-nfs/ -name "*.sql" -path "/backup-nfs/*.sql" -type f -mtime +1 -delete
* * * * * find /backup-nfs/ -name "*.sql" -type f -mtime +1 -delete
* * * * * find /backup-nfs/ -name "*.sql" -path "/backup-nfs/*.sql" -exec rm -rf {} \;
* * * * * find /backup-nfs/ -name "*.sql" -type f -mtime +1 -exec rm -rf {} \;

Note : i try those commands one at a time

all are not working. The same commands work on another 3 servers. But when they are executed on terminal like this find /backup-nfs/ -name "*.sql" -path "/backup-nfs/*.sql" -type file -mtime +1 -ls, they are just fine

What is wrong with this server? which log should I see?

thankyou

uz flag
Jos
Why do you think that they don't work? Do you get an error message? Are files not deleted? And another question: are you sure you want to execute each of these commands every minute within one hour?
David avatar
cn flag
There is no Ubuntu version 20.4
hr flag
`find -type file` tells me `find: Must separate multiple arguments to -type using: ','` - are you sure that shouldn't be `-type f` ?
codlord avatar
ru flag
Easiest way to find out what is going on is to always send output of cron jobs to log file/s. Like `* * * * * my_job > /path_to_logs/mylog.log 2>&1` or to append to a file use `* * * * * my_job >> /path_to_logs/mylog.log 2>&1` The environment that cron runs in is not the same as your shell so start by logging and see if that shows you the reason for the failure.
terdon avatar
cn flag
First check: 1) is cron installed and working? ii) Do any commands in a crontab work? iii) are there actually files to delete? If you remove the `-delete` and add `> /tmp/find.log` at the end, is a `/tmp/find.log` created and does it contain files that were found by `find`? iv) add a `> /tmp/find.log 2>&1` to the end and check `/tmp/find.log`. Any errors? And do you really have all of these commands? Some will give an error, and the rest are redundant.
padjee avatar
cf flag
@Jos . well, off course not. It is just for testing crontab only and I actually use `* * * * *`
padjee avatar
cf flag
@steeldriver . I am sure that the files that want to be deleted are there. I can find them by using `find /backup-nfs/ -name "*.sql" -type file -mtime +1 -ls`
padjee avatar
cf flag
hi @codlord . thanks for the insight. I will try it.
padjee avatar
cf flag
@terdon hi, i) cron does exist ii) other commands, like `pg_dump` and `pg_dumpall` work fine. iii) the files are there and waiting to meet their demise iv) allright, I will do that. thanks
cn flag
only 1 of the commands has an absolute path; it is best to do them all like that ;)
padjee avatar
cf flag
@Rinzwind yup, I do put absolute path for all of them, but still don't work
uz flag
Jos
What does `/var/log/syslog` say about these cron jobs?
padjee avatar
cf flag
after long winding road, I find the answer. it is so simple : `* * * * * find /backup-nfs/*.sql -mtime +1 -delete` . But, why does this one work?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.