1836444 Members
2322 Online
110100 Solutions
New Discussion

simple cron job

 
SOLVED
Go to solution
Shar Hunter
Frequent Advisor

simple cron job

I have a fax application running on our system, and it dumps the fax file to a directory I use for other stuff. I go in every day and delete the fax file receipts. They are always the exact same size '411'. I need help with the proper use of rm to remove files of a certian size. How do you issue the command? So I can put it in crontab, and save myself time.

Thanks.
I don't think I'm in Kansas anymore.
10 REPLIES 10
Pete Randall
Outstanding Contributor

Re: simple cron job

Troy,

Use find with -size c (for characters). See man find.

HTH,
Pete

Pete
Stefan Farrelly
Honored Contributor

Re: simple cron job

This script will do the job;

cd
ll|awk '{print $5" "$9}'|while read
do
read A B
[ $A -eq 411 ] && echo $B
done


The reason its done this way is to pump only the size and filenames into the while loop and if the size = 411 then remove the file ($B). Its very safe.

Im from Palmerston North, New Zealand, but somehow ended up in London...
PIYUSH D. PATEL
Honored Contributor

Re: simple cron job

Hi,

Login as root and give

# crontab -e

Then it will open a file and there you can type

30 21 * * * /usr/bin/rm

save the file an exit

Then your cron job will be activated at 21:30 daily

Piyush
Stefan Farrelly
Honored Contributor

Re: simple cron job

oops, change the echo $B to rm $B
Im from Palmerston North, New Zealand, but somehow ended up in London...
Steven Sim Kok Leong
Honored Contributor
Solution

Re: simple cron job

Hi,

Put this in your cron job:

cd /dir
rm -f `find . -size 411c -print`

Be sure to test it out by printing out the find output first i.e.

# cd /dir
# find . -size 411c -print

Hope this helps. Regards.

Steven Sim Kok Leong
Helen French
Honored Contributor

Re: simple cron job

Try this:

# cd dir
# find . -type f -size 411c -print (for testing)
# find . -type f -size 411c -exec rm {} \; ( for delete these files)
Life is a promise, fulfill it!
S.K. Chan
Honored Contributor

Re: simple cron job

Try this script ..(say "myscript")
#! /usr/bin/ksh

DIR=/tmp/apps
find $DIR -type f -size 411c -exec rm {} \;

And put this script in your cron (say 2pm everyday), assuming you're using root to run the cron ..

# crontab -e
==> add this line ..
00 14 * * * /bin/myscript
# crontab -l
==> check it ..
Ian Dennison_1
Honored Contributor

Re: simple cron job

Can't you switch off the receipts?

Share and Enjoy! Ian
Building a dumber user
Darrell Allen
Honored Contributor

Re: simple cron job

Hi Troy,

I like Ian's idea about disabling the receipts. Or perhaps writing them to a directory that is not used for anything else.

Barring those choices, the find is a good option. I would add the -name option (-name "wildcarded_name_here") presuming the file names have something unique to identify them. Is there something command in all the file names?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Shar Hunter
Frequent Advisor

Re: simple cron job

Thanks got it. Wilson and Leong gave me what I needed.

I simply did not know how to add file size tothe rm command.

The fax receipts have to go somewhere, and they do get looked at sometimes. Just wanted to remove them at the end of the day, to keep from filling a file folder, and also to not have to wade through them when looking for other stuff.

THanks for all the help.
I don't think I'm in Kansas anymore.