How to schedule a task for certain period of time

I want to schedule a command to run as a background job on each morning and wanna end it at midnight without using the kill command. Is there any way to use any command which will run for a specified period of time. Say from 9:00 a.m to 23:00 p.m. and then stops automatically because we people can't use the kill command in the server because boss doesn't allow it.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

might it be easier to have your script, or what have you, periodically check the time? That way you could use cron to start the job, and let the script take care of cleaning up after itself

redhat_786Author Commented:
There's nothing in the script but a single command i.e. "tail -f file1 > file2 & " which fetches only the appended data from the file and store it in the file2. It runs as a background job and I want to stop it working at midnight and then start it again on next morning as a new process.
Tail is not a daemon and will exit after it is finished.
So just make a crontab entry like:
*/10 9-23/1 * * * tail -f file1 > file2  
It will be executed every 10 minutes from 9 a.m. to 11 p.m.
Bob Gunzel
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

redhat_786Author Commented:
Sir, actually I want to schedule it to run as a background job and if I schedule it to run after ten minutes then it would return only ten last lines even if it has added more than 10 lines in the file which is made by online coming data. So please help me in this cause so that it keeps on running for a specified period of time. Thanks
You can daemonize any program by using daemontools, You can control the execution period with crontab and the svc program that comes with deamontools.
I recommend to use a script with a sleep statement. Otherwise disk-io and cpu usage may serverely hamper other

Bob Gunzel

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.