I've written the script that kick off through CRON job and kill itself by specific time.
I've start time and end time specify in env file.
i.e
START_TIME=1500 (03:00 PM)
END_TIME=0600 (06:00 AM)
It always works good if my START_TIME is before midnight and my END_TIME is after midnight.
I'm using follwing if condition to terminate my script.
if [ $CURRENT_TIME -gt $START_TIME ] || [ $CURRENT_TIME -lt $END_TIME ];
But if I wanted to change my START_TIME and END_TIME to like
START_TIME=1300 (01:00 PM)
END_TIME=1530 (03:30 PM)
then it's not follow the logic and script will run forever.
When job kick off through CRON then script will check that kick off time is after the START_TIME and before the END_TIME.
gives the current time in terms of seconds since 1970. So you can terminate your script in a spesific time. 1 hours is 3600 seconds so lets say to finish your script after 2 hours you have to calculate the current time again and compare it with (now+7200)
i just wanted to give an idea
regards
---------- Post updated at 11:11 PM ---------- Previous update was at 11:10 PM ----------
Those two are more concise, and accomplish the same thing ( return the seconds since the epoch 00:00:00 Jan 1, 1970 GMT, not counting leap seconds ).
The date command is GNU date 7.2 on Linux. Use Perl, if you are worried about portability of /bin/date
Here is a simple example of a perl script to do what you want:
this grabs the current epoch time and then executes the code in the do() block ( in this case, prints "foo" once every second ). It keeps doing this for 10 seconds total.
What you need to do is put the start time in as a field in your crontab which runs this job, and then calculate the offset in seconds from that time.
In the example you gave this is 60 seconds * 60 minutes * 15 hrs, or 54,000 seconds. that is what you should set $offset to.
I would actually set it, not "54,000" but the equation, as it helps you to see what is going on:
Hope that Helps
Last edited by deindorfer; 04-27-2010 at 05:54 PM..
Some versions of date don't have the %s (Solaris is one) modifier. Not all UNIX flavors have truss. I would recommend using the perl method deindorfer posted.
Thanks for the reply deindorfer!!!
I did understood your logic and it'll work if i only have to control the end time.
I'm sorry I mention CRON actually this job run through CA7 scheduler which is not in my control. CA7 will always kick off the job at specific time but as requirement I’ve to check in my script that kick off time is after the START_TIME.
As you said that convert the END_TIME in second (i.e. 60 * 60 * 15 = 54000 sec)
that means my job will run for 54000 seconds.
For example in my environment file I’ve
START_TIME=2100
END_TIME=0600
If I convert my END_TIME in seconds then it'll only run for 6 hours.
The user will put actual time to end the script they won't put the total hours to run the script.
I guess I may need to get the difference between START_TIME and END_TIME to get the total hours and then run the script for that total hours.
But I’m still stuck with that START_TIME comparison.
Hi,
I have to add 7 bases of specific nucleotide at the beginning and ending of all the fasta sequences of a file. For example, I have a multi fasta file namely test.fasta as given below
test.fasta
>TalAA18_Xoo_CIAT_NZ_CP033194.1:_2936369-2939570:+1... (1 Reply)
Hello beautiful people, I would like to kindly ask you to help me with my school leaving project. Unfortunatelly due to family problems I felt into trouble and I am on able to finish my project due to schedule.
I would like to ask you to review this script and give me any hints that you could.... (2 Replies)
Hi
This is my first post and I'm just a beginner. So please be nice to me.
I have a couple of html files where a pattern beginning with "http://www.site.com" and ending with "/resource.dat" is present on every 241st line. How do I extract this to a new text file?
I have tried sed -n 241,241p... (13 Replies)
Hi,
I am quit satisfied with this scrtipt and really don't want to change anything but the end. I get a repetitve option when I want to "quit"
and don't know why. What am I missing? When I press q to quit
with this script, I get an EXTRA "Enter " How do I correct this so that when I
press... (1 Reply)
Hello All,
I have written a script which which is working fine to a certain logic of it. But i want a part of the script to run two commands at 00:10 hrs every day. These two command are
1. rm -rf /path/to/folder
2. mail the content of a file.
How do i achieve this. Thanks.
... (4 Replies)
i want to make a script for grep any lines with key word and every time (5 min)
Ex. Log in Server.
.
.
.
03-01-2012 03:07:54,924 - INFO MessageUtil - Return | Status=0 | TxID=12010300000548755292 | Message=Success
03-01-2012 03:09:13,789 - INFO MessageUtil - Return | Status=0 |... (6 Replies)
Hi I have files that end with .txt.txt that i want to delete. But I also have files that end with .txt that I want to leave intact. How do I specifically delete files that end with .txt.txt in a folder.
thanks (5 Replies)
Hi all,
I am trying to end a Menu script. Can people suggest various methods please?
At the moment I am doing:
quit=n
while
do
...Code
Code
Code...
read userinput
case $userinput in
q|Q) quit=y;;
esac
done
But this doesn't seem to work every time, occasionally it will work,... (6 Replies)
Hi All,
I am having a script, which run fine. But what I want to do is that the script should run for specified time and terminate then ( say for a minute).
Can somebody help me for this. I would be greatful.
Thanks,
Aru (8 Replies)
Okay I have this script file that runs from cron and most the time it works just find. Except every so often one of the three ssh commands I have in it just doesn't know it's done and that of course causes the whole thing to hang!
The ssh command has executed. I can tell this because the command... (1 Reply)