Question

Currently have this in my Debian cron:

*/1 * * * * [ -s /tmp/#sql_362_0.MYD ] || rm -f /tmp/#sql_362_0.MYD

I'd like to replace it so that it deletes any file matching #sql_*.MYD. I only want to delete the file if it's empty.

I assume if I did:

*/1 * * * * [ -s /tmp/#sql_*.MYD ] || rm -f /tmp/#sql_*.MYD

It'd delete all matching files, if just one of them is empty? That is not what I want.

Side note - this is to a band aid to an issue where MYSQL creates a temp file, that ends up taking the entire site down. After many hours couldn't find a proper fix.

Was it helpful?

Solution

using find should do the work.

*/1 * * * * find /tmp/ -maxdepth 1 -type f -name '#sql_*.MYD' -empty -delete

-maxdepth 1: do not find file in subdirectory

-type f: matches only regular file (no directory, no symbolic link, and so on)

-name <pattern>: matches the file name pattern

-empty: matches only empty file

-delete: delete that file

see man find for detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top