LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2006, 12:16 PM   #1
meniscus
Member
 
Registered: May 2006
Posts: 70

Rep: Reputation: 15
Place a timeout on a script?


How do you place a timeout on a script? Lets say ur using tail -f to follow a process but you want the process to end after 12hours nomatter what. or is it even possible?
 
Old 10-05-2006, 12:39 PM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

There are some limits that can imposed on processes, but I don't think that wall-clock time is one of them. I'd certainly like to hear if there is some such facility.
Code:
       ulimit [-SHacdflmnpstuv [limit]]
              Provides  control  over the resources available to the shell and
              to processes started by it, on systems that allow such  control.
  -- man bash builtin
Off the top of my head - if I were faced with this, I think I would write a script that calls another script that actually does the work, like the tail. The first script would then use the process ID of the second to pass into an at (and friends) command, which would then wake up at the specific time later, and kill the process.

I'd use either the tail or perhaps sleep for testing.

If you choose this, let us know how it works out. I suspect others may have some ideas as well ... cheers, makyo
 
Old 10-05-2006, 02:09 PM   #3
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 727

Rep: Reputation: 74
Hi.

If you are not comfortable writing a script version, here's a manual procedure.

In one window, you run a command, say:
Code:
sleep 1000
So that's now running in the foreground in that window. In another window, you enter:
Code:
% ps -u makyo | grep sleep
substituting your name for makyo, the command you enter for sleep, etc. That produces:
Code:
23040 pts/2    00:00:00 sleep
That gives you the process ID, 23040. Now you enter the scheduling command and whatever time you like, for example:
Code:
% at now + 1 minute
which will prompt you for commands. You enter whatever
you wish, and terminate with ^D:
Code:
at> kill 23040
at> <EOT>
which will produce a message:
Code:
job 13 at 2006-10-05 12:54
The original process continues until the time you specified, then it runs your sequence of at commands, which, in this example, kills the sleep process 23040. The at command is very friendly with time options: minutes, hours, etc., see man at for more details ... cheers, makyo
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where to place certiain commands inside shell script beeblequix Linux - Newbie 8 08-10-2006 12:12 PM
script 'prompting with timeout' question WindowBreaker Slackware 2 03-09-2006 01:44 PM
what script to place this command? fuzzhead85 Mandriva 1 03-24-2005 12:39 AM
Script for voice modem to place a call masterJ Linux - General 1 07-27-2004 05:23 AM
PHP script timeout J_Szucs Linux - Software 4 01-22-2004 05:10 PM


All times are GMT -5. The time now is 02:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration