Running a process based on time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a process based on time
# 1  
Old 12-07-2010
Running a process based on time

Hello All,

My script is nearly complete, there is just one last piece that needs to be added in.

I need to check for the time, and if it is lets say for example. Sunday at 5:00AM, my script cannot run.

I would assume it would be something like this, parden the terrible pseudocode

check the time
if the time is sunday between 5am and 8am
Do nothing
if else
do the regular scripting.

whats the best way to get started doing this?
# 2  
Old 12-07-2010
Well, if you want downtime, make a separate marker file with a state indicator, so you can turn it off unconditionally or allow it to run. Then you can have cron jobs change the state, or you can take it down during special maintenance.

What asks this script to run?
# 3  
Old 12-07-2010
Code:
Now=$(date +%u%H) # %u: 1..7 1 is Monday, %H: Hour 00..23
if [ $Now -lt 705 ] || [ $Now -gt 708 ] # 705: sunday 5 AM, 708 ... 8 AM
then 
   # do regular scripting
fi


Last edited by frans; 12-08-2010 at 02:31 AM..
# 4  
Old 12-07-2010
Not sure if your script need be run regularly. Do you need the backup between 5am ~ 8am? If it is, to put it in cronjob will be good idea, with that you needn't change your code if the time is changed in the future. For example, the backup time is changed.

Code:
0 0-4,9-23 * * 0 /PATH/your_script

# 5  
Old 12-07-2010
Quote:
Originally Posted by frans
Code:
Now=$(date +%u%H) # %u: 1..7 1 is Monday, %H: Hour 00..23
if [ $Now -lt 705 ] && [ $Now -gt 708 ] # 705: sunday 5 AM, 708 ... 8 AM
then 
   # do regular scripting
fi

How can $Now be both less than 705 and greater than 708?

rdcwayx, it sounds like this script is a start/login script that probably runs from .profile. If this is the case, scheduling it to run via cron is unlikley to be usefull.

I think DGPickett is on the right path have your backup (or whatever else is running at 5am Sunday) create a lockfile and check it with the start/login script, that way you can also stop it running for other ad-hoc maintence, or whatever.

Last edited by Chubler_XL; 12-07-2010 at 08:11 PM..
# 6  
Old 12-08-2010
Quote:
Originally Posted by Chubler_XL
How can $Now be both less than 705 and greater than 708?
Smilie I forgot to change the AND in OR when inverting the condition !
I Corrected the original post.
# 7  
Old 12-08-2010
Yes, this is the toe of the "I wish I had a scheduler" problem, where you need to control and track many things running periodically, more elaborately than cron, be able to layer schedules, stop scheduling, run later or rerun tasks that can be focused on their original time(s) and restart running tasks that are truly real time, possibly with an immediate run off-cycle to minimize the gap. For instance, disk cleanup tasks are in the latter group (real time), and shift reports are in the former group (can have a date and shift as arguments, make aggregate rows in a db for one shift). If the maintenance takes 10 hours not 8, you do not want things taking off after 8, as the cleanup may take hours. Then, there is the possibbility of creating job dependencies, so b for today does not run until a for today and b for yesterday run OK. You can even have it mark dependent jobs not run if you mark a run as defective, automating catch up reruns. Optimally, it also provides you with a database of run times and outlooks that can drive scheduling choices and resource management as well as reruns, perhaps after a problem is fixed, and even load factors to drive smart scheduling.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Killing the process if running for long time in script

I am running a script which will read the data from fail line by line and call the Java program by providing the arguments from the each line. The Java code is working fast for few records and for some records its getting hanged not providing response for morethan one hour. Currently am... (4 Replies)
Discussion started by: dineshaila
4 Replies

2. Shell Programming and Scripting

Get how much time process has been running in seconds

I use this command to get the time elapsed for a process ps -eo pid,pcpu,pmem,user,args,etime,cmd --sort=start_time | grep perl It gives in format 19990 0.0 0.0 user /usr/bin/php 5-09:58:51 /usr/bin/php I need in seconds. Please use CODE tags for sample input and output as well... (2 Replies)
Discussion started by: anil510
2 Replies

3. Shell Programming and Scripting

Process running time by taking user input

Need help in scripting . Below is the situation and need your inputs Checking all the processes, scripts running time based on user input time . Below Example ps -aef -o user,pid,etime,stime,args| grep sleep <user> 28995 01:24 14:14:39 sleep 120 <user> 29385 00:52 14:15:10... (8 Replies)
Discussion started by: ajayram_arya
8 Replies

4. Shell Programming and Scripting

Process running more than require time

Frineds I need assistance in writing a script . Newbie to scripting. How to find list of processes that are running more than an hour . Below i used the step to get the etime and stime . Now by getting the result i need to display longer time process with full listing. ps -aef -o... (10 Replies)
Discussion started by: ajayram_arya
10 Replies

5. Shell Programming and Scripting

Help with kill a specific process after certain running time

Hi, Do anybody experience to write a bash script in order to kill a specific process (java) after certain time of running? eg. java java.jar task_run.txt I will run a java program (java.jar) which will run a long list of process (task_run.txt) one by one. I plan to terminate the java... (5 Replies)
Discussion started by: perl_beginner
5 Replies

6. UNIX for Dummies Questions & Answers

How to get the start time for a JAVA Main running process

I have a script that executes a MAIN JAVA FILE It does check if the process is already running or not by using this code w_pid=`ps -efx | grep -v grep | grep "FileTransactionArchiveMain dvlp"|awk '{print $11}'` if then #echo 'Another instance is running.' exit fi Now I... (1 Reply)
Discussion started by: akabir77
1 Replies

7. UNIX for Dummies Questions & Answers

how to get start time of a running process

I am trying to see if a process is running what was its start time. here is the code that I am using if then echo 'Gateway output processing started.' else VAR=$(ps -ef | grep batch_output_x ) ... fi now the problem i see is when the process is running i get two... (3 Replies)
Discussion started by: akabir77
3 Replies

8. Shell Programming and Scripting

keeping 10 process running at the same time

Hi guys, I neet to run sqlldr to charge about 50,000 files every day to my DWH, so I need to make an script to keep about 100 processes of sqlldr running at the same time. So, the issue is that i've been trying for a few days to make an script which can keep that amount of processes running, so... (2 Replies)
Discussion started by: razziel
2 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. UNIX for Dummies Questions & Answers

is there any way to know how much time process was running from the moment it started

i have process that was started few days ago , is there way to know by its id how long it was alive in the system ? Thanks (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question