1832902 Members
2452 Online
110048 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

shell script

Hi All,

I find that in one of my server /var/spool/cron/tmp is growing very fast and sometime new files are created and which grows too.

Pls. note sometime new files are generated in /var/spool/cron/tmp.

I am looking for a shell script which will read all the files under /var/spool/cron/tmp and trim them to 0KB.

I want to schedule this script to run once a day.

Thanks and pts in advance.
Everything is possible
9 REPLIES 9
Kenneth_19
Trusted Contributor
Solution

Re: shell script

Hi,

That's easy:

for FILE in `ls /var/spool/cron/tmp`
do
cat /dev/null > $FILE
done

That's it!

Kenneth
Always take care of your dearest before it is too late
Fragon
Trusted Contributor

Re: shell script

Hi,make a script first (cutcron.sh):
#!/usr/bin/sh
for fn_name in /var/spool/cron/tmp
do
> /var/spool/cron/tmp/$fn_name
done

The make a cron to run this script:
#chmod 755 cutcron.sh
#crontab -e
0 0 * * 0-6 /cutcron.sh

Is this really you need?

-ux
Steven E. Protter
Exalted Contributor

Re: shell script

What you need is a find command.

This is not exact because my HP box isn't built yet.

find /var/spool/cron/tmp +msize ### -exec rm {} \;

That is the basic structure. You may want to make a list for later removal instead of zapping the files straight away.

Also, I forget right now whether msize is in kilobytes or what, so play around a bit.

This is a good way to go though.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Michael Tully
Honored Contributor

Re: shell script

Have a look at this one:

http://www.introcomp.co.uk/examples/logrotate.html
Anyone for a Mutiny ?
Ramkumar Devanathan
Honored Contributor

Re: shell script

for file in /var/spool/cron/tmp/*
do
> $file
done

HTH
- ramd.
HPE Software Rocks!
Michael Tully
Honored Contributor

Re: shell script

Try this script from here:

http://www.introcomp.co.uk/examples/logrotate.html

You will need to make some modifications.
Anyone for a Mutiny ?
Stefan Schulz
Honored Contributor

Re: shell script

Hi,

you got a lot of replys how to trim your tempfiles. But i think it would be better to check why these files are created. It should be possible to find a configuration where these files are not created in the first place.

check your crontabs. I think the "problem" could be that you don't redirect your STDERR to a file or /dev/null.

Do something like this:

1 23 * * 1-5 yourscript 2> /dev/null

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Sanjiv Sharma_1
Honored Contributor

Re: shell script

Thanks Kenneth.
Everything is possible
Caesar_3
Esteemed Contributor

Re: shell script

Hello!

for file in /var/spool/cron/tmp/*
do
> /var/spool/cron/tmp/${file}
done

will truncate all files in /var/spool/cron/tmp

Caesar