LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Cron Job with a Script (https://www.linuxquestions.org/questions/linux-general-1/cron-job-with-a-script-349980/)

bravored 08-04-2005 01:14 PM

Cron Job with a Script
 
Hi All,

I like to create a cron tab to a script

if df = 97%
goto /var/log
delete *.logs
and reboot

Anyone know how to create a script like that?
If so how to do it? What is the command line?

Also it needs to be scheduled every 2 weeks.
I dont see oen for "weekly"

Thanks
Joe

tangle 08-04-2005 02:30 PM

I am not sure what log files you are deleting, but you might want to check out logrotate.

If that doesn't work you could do something like this and put in a script and schedule a cron job.
Code:

# find files older than 7 days and delete them
find /tmp -type f -mtime +7 | xargs -- rm -f --

Here are the commands that would go with the list you posted.
Code:

df = 97%            df -h shows disk usage
goto /var/log      cd /var/log changes the directory to /var/log
delete *.logs      rm *.log removes all files with the extention .log
and reboot          reboot reboots the box


If you want to schedule it in cron, here is a how to for cron.
http://aplawrence.com/Basics/bbcronbasics.html

Here are 2 guides for bash scripting.
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/abs/html/

bravored 08-04-2005 02:37 PM

Hi

Thanks for emailing back.

This line= # find files older than 7 days and delete them
find /tmp -type f -mtime +7 | xargs -- rm -f --

seems to bea good idea for me.

Basically, i have a script in /root/reboot.sh

---cd /var/log/log.*
reboot

The log files are created as a result of other scripts to keep track etc.. proprietary u can say so its ok to delete them

I want to a "crontab" to ro run the reboot.sh every 2 weeks. I was reading to crontab I dont see option for every 2 weeks.

I saw @weekly how would I put that in place?

Bottom line is i need a delete and reboot done every 2 weeks? Can a crontab do it? What is the command line?

Thanks for your thoughts
Joe

tangle 08-04-2005 03:00 PM

I believe that you would have to schedule one job for the 1st day and on job for the 15th day.

05 00 01 00 * /usr/sbin/<script name> # day 1
05 00 15 00 * /usr/sbin/<script name> # day15

You need to put this in your crontab file. Do a slocate crontab to find it.

I would look into logrotate for rotating the logs and use cron to reboot the system.

Just curious, why do you need to reboot every 2 weeks?

bravored 08-05-2005 10:27 AM

I think log level for message is set too high or something

/dev/hda --get to 100% and stops people from going yahoo.com etc external sites
so we have to delete the messages log and reboot the system


anyway I can give more space to the hda?

thanks


All times are GMT -5. The time now is 11:24 PM.