1

I am learning Python on my own and running on RedHat linux 6.6 so please bear with me.

I wish to try and use Python to delete certain files in our file system whose filenames and type are stored as hash values and the path to these files in a database (MySQL 5.5).

For example, I have 5 files and I wish to delete the automated ones and their hash filenames & types are:

52c62e759abfb47ec0fae3e9f1525b3b8e347054 | manual

aa91f74f2028d254a700300a8a012f64f9535b3b | automated

ffa9c58f7231caab6836ed4baaf61c95e9763af2 | automated

71c3251aba5848e4188c0f542ea0b91be224d750 | manual

a214f7be544d0e73307e7abff9327226cca30e35 | automated

and so forth ...

The files are located in the root prefixed "/srv/ourfiles/data"

We take the first 2 characters in the string and that is the top folder and the subfolder, are the next 2 characters and that is where the files are stored.

The 1st file is located at: "/srv/ourfiles/data/52/c6"

The 2nd file is located at: "/srv/ourfiles/data/aa/91"

The 3rd file is located at: "/srv/ourfiles/data/ff/a9"

The 4th file is located at: "/srv/ourfiles/data/71/c3"

The 5th file is located at: "/srv/ourfiles/data/a2/14"

and so forth ...

How do I connect query against the database (I know what the query is so its just how to connect)?

Get the result set and iterate through each of the 3 automated files I wish to delete and compare the filename stored in the database with the actual filename in the path that they match?,

and finally delete the file itself?

I want to run this as cron job if possible.

Thank you!

Lawrence
  • 119
  • 1
  • 1
  • 6

0 Answers0