Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to schedule a task for certain period of time

Posted on 2003-03-25
Medium Priority
Last Modified: 2013-12-15
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.
Question by:redhat_786

Expert Comment

ID: 8208904
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


Author Comment

ID: 8209068
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.

Expert Comment

ID: 8213477
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!


Author Comment

ID: 8215545
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

Accepted Solution

bobgunzel earned 160 total points
ID: 8218224
You can daemonize any program by using daemontools,
http://cr.yp.to/daemontools.html. 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

Expert Comment

ID: 9076588
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.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension . This reminded me of questions that come up here at EE along the lines of, "How can I tell the type of file from its cont…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question