Shell Script Run Interval to be dynamic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script Run Interval to be dynamic
# 1  
Old 11-28-2005
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.
# 2  
Old 11-28-2005
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.
# 3  
Old 11-28-2005
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 ...
# 4  
Old 12-19-2005
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.
# 5  
Old 12-19-2005
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.
# 6  
Old 12-19-2005
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Run Bash Script thrice & then interval for 10 mins.

Hi... I am very new to shell scripting. I have written a script with help of this forum and some googling and it works the way I want it to. Currently this script checks for my SIP trunk registration every 5 seconds, if registration is not available then it reboots my router through telnet... (4 Replies)
Discussion started by: jeetz
4 Replies

3. Shell Programming and Scripting

Main script triggers second and it has to run at specific interval

Hi Friends, I am newbie to shell programming and I am stuck trying to accomplish following task.We use Bamboo CI which executes script1 passing parameters. This Main script executes script2 as backend process as part of one of it statements. Task of script2 is to essentially check whether a... (0 Replies)
Discussion started by: aditya206
0 Replies

4. Shell Programming and Scripting

How to run a script everyday between 7 and 8 pm with the time interval of 5 minutes?

Hi, Can someone help me in running a cronjob everyday between 7 and 8 pm with the time interval of 5 minutes in between to repeat that script. The script is so small and I need that to run daily between this time. Please if possible provide me the syntax for this logic. Thanks. (4 Replies)
Discussion started by: cya
4 Replies

5. Shell Programming and Scripting

Shell script dynamic command

I need to run a shell script with dynamic command in it like # Begin script... mysql xx "select * from tab" | sed 's/\t/|/g' > GENERATED_20100304.txt the dynamic part is 20100304 which should be today's date, and it needs to run every day and create a new file with... (2 Replies)
Discussion started by: nuthalapati
2 Replies

6. UNIX for Dummies Questions & Answers

Run script in the background with a time interval

I have a script I want to run in the background, and I have looked it up but I am not exactly sure how to do. First of all to run it in the background do you have to put something in the script or is it just a command when you go to run it. I found this solution to it but once again I am not to... (2 Replies)
Discussion started by: mauler123
2 Replies

7. Shell Programming and Scripting

run script 1 minute interval without CronTab

I am using Solaris 9. I wish to run my script every 1 minute inteval. Though i can run it using below entry in crontab. * * * * /export/home/username/script/file_exist_&_run.sh in short above script will check whether a specific file exist in a directory. If it found it will inovke another... (10 Replies)
Discussion started by: thepurple
10 Replies

8. Shell Programming and Scripting

script to run repeatedly after a fixed interval of time

Hi , I am working on the following script . I want this script to run and scan the log file repeatedly after 3 hours. This script will run & scan just for the current date logs and after every 3 hours. Kindly advice what to add in this script for this purpose. #!/bin/sh diff common.log... (3 Replies)
Discussion started by: himvat
3 Replies

9. Shell Programming and Scripting

dynamic editing using shell script

Hi, I would like to edit an input data-file by changing a variable in it in steps: For ex: If my input file is 'big.in', then it has the following data: 2.54 0.01 0.5 0.0 My source code then reads this above line, executes and gives out some output. Then , I want to increment... (1 Reply)
Discussion started by: habzone2007
1 Replies

10. Shell Programming and Scripting

creating dynamic shell script

Hello I am trying to create a dynamic ksh script and I have an issue. I have a script a.ksh and it has got the following lines (for example) #!/bin/ksh # trace mode +x : without trace -x : with trace set +xv echo hi, i am going to create a dynamic script now cat >> dynamic.ks <<EOF... (2 Replies)
Discussion started by: sundarkumars
2 Replies
Login or Register to Ask a Question