The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
dynamic editing using shell script habzone2007 Shell Programming and Scripting 1 05-14-2008 07:55 PM
creating dynamic shell script sundarkumars Shell Programming and Scripting 2 02-13-2008 08:28 AM
passing a list of dynamic names to a "PS" command in shell script? sachin.tendulka Shell Programming and Scripting 3 11-21-2007 01:18 AM
Dynamic variables within shell script isingh786 Shell Programming and Scripting 2 01-25-2007 06:44 AM
search and replace dynamic data in a shell script csejl Shell Programming and Scripting 8 10-21-2003 07:33 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-28-2005
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 156
Question Shell Script Run Interval to be dynamic

Hi All.

I have a script which has to be run periodically. The frequency of its run will be decided by a Database stored value PollRate.
e.g. If PollRate value is 300secs, then the script should be executed every 5 minutes, if it's 1500secs, it should execute every 15 minutes.

Is there anyway, by which the crontab entry for the script can be modified everytime the DB value changes.

If not, then I think I will have to run the script in an infinite loop and at the end of the loop would have to specify a sleep for the value of the PollRate field.
The Problem with the above approach is that everytime the script exits abruptly, it will have to be maunally restarted.

Please suggest a simple and robust solution.

Thanks,
Rahul.
Reply With Quote
Forum Sponsor
  #2  
Old 11-28-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
Let's say that your script is /home/joe/bin/something. Somehow you need a way to get the interval into a variable called INTERVAL. So then:

#! /usr/bin/ksh
exec >/dev/null 2>&1
INTERVAL=$(get.interval.somehow)
echo /home/joe/bin/something | at now +"$((INTERVAL/60))" minutes

as the first few lines of /home/joe/bin/something will cause the script to reschedule itself based on the current interval. This is untested, but I think it should work.
Reply With Quote
  #3  
Old 11-28-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
i was going to suggest a way to edit the crontabs but Perderabo's at solution might actually be better for your situation ... with a slight modification ...

to get your script to start automatically after booting up, create a script in /etc/rc3.d to do that for you ... please see other scripts in that directory for proper formatting and naming and also "man init" ...

... then go with Perderabo's script ...

doing so will allow you the flexibility to change the polling intervals as required without having to manually start the process after a reboot ...
Reply With Quote
  #4  
Old 12-19-2005
Registered User
 

Join Date: Sep 2004
Location: Mumbai-India
Posts: 156
Din't get how to use it in my script

Hi Perderabo,

I dint get how can I use this in my script.

This is the cron for my current script
00,05,10,15,20,25,30,35,40,45,50,55 * * * * . $HOME/db-bin/controller.sh

This script is currently every 5 minutes.


In this script I call, three other shell scripts.

NOw, How do i schedule a cron. And if from the above method, no cron is needed, how will i take care if the script has exited abruptly?

What I thought was, I can scehdule a cron for every minute.i.e the Interval cannot be less than a minute.
Then I can log the last_run_time in the database and run it if the interval from the last run time is completed.

Thanks,
Rahul.
Reply With Quote
  #5  
Old 12-19-2005
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,667
My idea does not involve cron (except that at command needs cron running). I explained it as well as I could. The only murky part is how know when to rerun the script and I do not understand your scheme so I can't elaborate on that.
Reply With Quote
  #6  
Old 12-19-2005
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
how bt executing a script at the end of your script which sets the env variable INTERVAL
dunno if cron or at can read env variables as its parameter, but if yes, then i guess this should do the trick

try these steps:
(my knowledge on cron is very very limited, so am really not sure if env variables are supported by cron)

INTERVAL=5 # first value
cron entry uses $INTERVAL
your script runs, at the end calls database qry to set INTERVAL to value from database.


lemme know if this works, I ll atleast know then if cron can accept environment parameters
__________________
War doesnt determine who is right, it determines who is left
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0