We are logging some files using ftp to our ISP's server. This work fine, but we need to perform some automatic housekeeping - that is: delete files older than 7 days / moving files to subfolders.
This has proven to be a very difficult, as there is only ftp access which can be done automatic - and after lots of internet searches we decided to rotate folders instead.
Also, we would like to set this up from our home-server running Ubuntu Linux and using a bash script. Both tools are rather new knowledge, but after some heavy googling there may be a way out ;-)
Update I: First try was partly successfull....
Update II: Second try - sucess!! The answer is: Kermit!
To sum up, the solution should be
- create folder for storing of new files
- decide on number of days history
- create a bash script to be run at midnight doing the 'stuff'
In this example working folder is 'log' and we decide on 7 days of history. History folders are named 'log-1' for yesterday - to 'log-7'
Now we create a bash script doing following steps
- start ftp (glob ON, interactive OFF)
- connect to server
- cd log-7
- mdelete *
- cd ..
- rmdir log-7
- rename log-6 log-7
- rename log log-1
- mkdir log
That is it. Simple. Of course in our case it is no problem if we should loose a single transaction during step 9 and 10. This might be different for you!
One word of caution: I have not made this yet - that is the bash part. All ftp fuctionality has been tested (using commandline access) and works fine. So - in theory this should work! Look for update to this article when i get the time for fidling with my second bash script... (first one is doing SQL backup from ISP using mysqldump to local server! Nice...)
A few links:
OK - first try worked in principle. Unfortunately I did not think of verifying existence of folders, so step 3 left me in 'root' and step 4 deleted the wrong files... I have to find a way to test for existence - that should do it.
After some more extensive googling it seems it is not possible to do this using ftp client. No error checking possible.
BUT help is near - Kermit is here! An article pointed me to Kermit - a script capable kommunication client - and it works! Updaete with links and script to follow - but if in trouble - google ckermit on Ubuntu platform.