1. Add the following line to /etc/crontab
*/1 * * * * root /etc/cron.minutely
2. Create the a file named /etc/cron.minutely
3.
Paste the script in the /etc/cron.minutely file.
Here are some
sample scripts:
#!/bin/bash
if
tail -20 /var/log/apache2/error_log |grep "Segmentation fault";
then
echo "iPrint and Apache were restarted $(date '+%m/%d/%y
%H:%M:%S')" >> /tmp/iPrintRestart.log
rcapache2
restart
wait
rcnovell-ipsmd restart
fi
==============
#!/bin/bash
ps
-ef | grep ipsmd > /tmp/ipsmdCheck
if tail -2 /tmp/ipsmdCheck
|grep "defunct"; then
echo "The Print Manager
process (ipsmd) was defunct; Print Manager restarted $(date
'+%m/%d/%y %H:%M:%S')" >>
/tmp/iPrintRestart.log
rcnovell-ipsmd restart
fi
4.
Change the rights on /etc/cron.minutely
chmod 755 /etc/cron.minutely
5.
Restart cron
cd /etc/init.d
./cron
restart
=========================================================
Example
to delete apache logs greater than 5 days and to run that command
every month.
1. Create a file named ApacheLogRotateDelete in the
/etc/cron.monthly directory.
2. Paste the following into that
ApacheLogRotateDelete file:
#!/bin/bash
find /var/log/apache2/*
-mtime +5 -exec rm {} \;
3. Change the rights on
/etc/cron.monthly/ApacheLogRotateDelete
chmod 755
/etc/cron.monthly/ApacheLogRotateDelete
4. Restart cron
cd
/etc/init.d
./cron restart
NOTES:
Which
files to delete:
The "find /var/log/apache2/* -mtime +5 -exec
rm {} \;" line causes all files greater than 5 days old to be
deleted. You can change the number of days by changing +5 to +10 for
days, or +x for some other number of days.
How
often to delete:
The instructions above cause the
ApacheLogRotateDelete script to run every Month. You can have that
run daily or weekly by using the cron.daily or cron.weekly directory.