Cleaning up ipfm files

Support section for FREESCO v0.4.x 3rd Party Packages

Cleaning up ipfm files

Postby bec » Thu Dec 31, 2009 10:43 pm

Hi,

I'd like to clean up some ipfm log files. Although I can usually stumble my way around Linux I'm confused by the cut down commands available in Freesco. I understand why there are the cutdown options, just struggling to know how to proceed. So far I have thought about 2 methods:
* Create a cron job that runs the following daily:
Code: Select all
find  /usr/local/ipfm/var/log -mtime +120 '!*' -exec rm -f {} \;

This doesn't seem to work as the find command from busybox v.06 doesn't seem to have the -mtime switch.

*write a command file that can be called by cron job (probably monthly).
The sort of steps I envisaged are:
Code: Select all
#Collect Month & Year
 month=date +%-d
 year=date +%y
 If month is <=3 (ie Jan or Feb or Mar) then subtract 1 from year (use last year)
 year=year-1
 
 #Now set month to delete
 If mon >3
 then mon_del=mon-3
 elseif mon_del=mon+9
 
 if mon_del <10 pad leading 0  # not sure how to do this!
 
# Now delete using this format: rm /usr/local/ipfm/var/log/2009_05* -r
 
rm /usr/local/ipfm/var/log/$year_$mon_del* -r  # Is this the right way to concatenate variables to create a command?

All of the examples I can find set this up using a file that starts with: #!/bin/bash

Am I on the correct track, or is there a better way to go? Which shells are available on Freesco?

Thanks for your patience and help
Brian
User avatar
bec
Member
 
Posts: 68
Joined: Sat Jun 29, 2002 8:37 am
Location: Melbourne, Australia

Re: Cleaning up ipfm files

Postby Lightning » Fri Jan 01, 2010 12:07 am

The simplest thing to do is to install the full "find" binary rather than running the stripped down version. This can be done easily with
Code: Select all
cd /boot/bin
snarf http://lewys-spot.dyndns.org/packages/0.4.x/non-packages/find.gz
zcat < find.gz > find
rm find.gz
chmod +x find
sync

As for the shells included with FREESCO. "ash" is the only stock shell and it is almost identical to all "bash" commands.
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 12079
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cleaning up ipfm files

Postby bec » Fri Jan 01, 2010 7:58 am

Lightning,

Thanks for this. An update (for those who might follow) and a question:

The updates:
1. The snarf command needs 1 less 's'. The directory is 'non-package'
Code: Select all
snarf http://lewys-spot.dyndns.org/packages/0.4.x/non-package/find.gz

2. I needed to delete or remove the copy of find in /bin before it would find the updated version in /boot/bin

The question:
The command works except that the timezone causes an issue. I am GMT+10, so 2 of the files in a directory are written 'a day' earlier than the specified date by -mtime 120, so they are not deleted today. ie 22 files are deleted in 'todays' directory and 2 from 'yesterday's directory. The 2 files left will be deleted tomorrow, however tomorrow the modifed date of directory is no longer 120 days ago, it is now 1 day ago as we changed the files in it yesterday. So the directory for the day is never deleted. The following seems to work (at least at the command line, I haven't tried it in cron yet).
Code: Select all
find  /usr/local/ipfm/var/log -mtime +120 -type d -exec rm -r {} \;

There is an error about the file or directory not existing, however it still seems to work.
Is there a way I can improve this?

Thanks
Brian
User avatar
bec
Member
 
Posts: 68
Joined: Sat Jun 29, 2002 8:37 am
Location: Melbourne, Australia

Re: Cleaning up ipfm files

Postby Lightning » Fri Jan 01, 2010 11:14 am

rm -r
I doubt that you really need the -r flag and if you use the -f flag instead it will not show bogus errors.

. I needed to delete or remove the copy of find in /bin before it would find the updated version in /boot/bin
No that is not the case, once a binary is put in the /boot/bin/ directory it will always be the one that is used when called from the command line or script unless the full PATH is used. /boot/bin/ is the first directory the system searches for files. You can test this with

which find
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 12079
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cleaning up ipfm files

Postby bec » Fri Jan 01, 2010 8:37 pm

Thanks again.

Using rm -f doesn't seem to work, I get an error message saying:
Code: Select all
rm: /usr/local/ipfm/var/log/2009_07_06: is a directory

with nothing deleted. Perhaps this is a limitation of the rm command from Busybox v.60? I'll live with -r and the error message.

I've reinstated the find back in /bin and you are correct it works (ie the version in /boot/bin is found). I'd like to know what has changed because I tested it 3 or 4 times with find --help immediately I'd unpacked the new version and each time received the help text for BusyBox v.60. That was when I tried renaming the version in /bin. Does Linux check the path every time or could the difference be that I've logged off and back on and it has re-checked the path? Anyway it is back working now.

Your help is appreciated greatly.

Brian
User avatar
bec
Member
 
Posts: 68
Joined: Sat Jun 29, 2002 8:37 am
Location: Melbourne, Australia

Re: Cleaning up ipfm files

Postby Lightning » Fri Jan 01, 2010 10:18 pm

The PATH is check at every execution, so I am at a loss as to why it acted that way before on your system.
As for the -f flag I did not realize it was a directory and you are correct, however you can use the -rf flag. r=recursive f=force so that the error messages will go away.
If you are afraid that you might make a mistake. The chances are high that you will never learn anything.
User avatar
Lightning
FREESCO GOD !!
 
Posts: 12079
Joined: Wed Nov 14, 2001 6:50 am
Location: Oregon, USA

Re: Cleaning up ipfm files

Postby bec » Sat Jan 02, 2010 12:34 am

Again thank you.

I selected the directory only and delete it with the files in it in one go to fix the problem identified above where 2 files are left behind and hence the directory doesn't get deleted. By filtering to just identify the directory and deleting it with -r or -rf the directory and files go in one hit.

When I execute
Code: Select all
rm -rf /usr/local/ipfm/var/log/2009_07_09
from the command line the error doesn't occur, however the command
Code: Select all
find  /usr/local/ipfm/var/log -mtime +175 -type d -exec rm -rf {} \;
, which evalutes to the same thing still seems to give the error. So there must be something different in what is passed to -exec from what is displayed on screen by find. NB my endgame is -mtime at 120, but I've been nibbling off the directories 1 at a time as I've tested various options. That is why the above shows -mtine at 175.


I'm happy with what I have, now I'll put it in as a cron job and clean up ipfm logs magically.

Thanks again.
Brian
User avatar
bec
Member
 
Posts: 68
Joined: Sat Jun 29, 2002 8:37 am
Location: Melbourne, Australia


Return to 3rd Party Package Support for FREESCO v0.4.x

Who is online

Users browsing this forum: No registered users and 3 guests

cron