LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-04-2005, 02:14 PM   #1
bravored
LQ Newbie
 
Registered: Mar 2005
Posts: 25

Rep: Reputation: 0
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
 
Old 08-04-2005, 03:30 PM   #2
tangle
Senior Member
 
Registered: Apr 2002
Location: Smithville, TN
Distribution: Slackware
Posts: 1,745

Rep: Reputation: 71
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/
 
Old 08-04-2005, 03:37 PM   #3
bravored
LQ Newbie
 
Registered: Mar 2005
Posts: 25

Original Poster
Rep: Reputation: 0
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
 
Old 08-04-2005, 04:00 PM   #4
tangle
Senior Member
 
Registered: Apr 2002
Location: Smithville, TN
Distribution: Slackware
Posts: 1,745

Rep: Reputation: 71
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?
 
Old 08-05-2005, 11:27 AM   #5
bravored
LQ Newbie
 
Registered: Mar 2005
Posts: 25

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cron job for expect script ruchitadesai Programming 9 05-27-2005 05:34 AM
Cron Job not running ssh script karim0028 Linux - General 3 02-07-2005 01:08 PM
Trouble with perl script in Cron job thack111 Linux - General 7 11-25-2004 03:44 AM
script not running as a cron job sanjith11 Programming 5 11-23-2004 09:42 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 12:21 PM


All times are GMT -5. The time now is 04:10 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration