LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2004, 03:09 PM   #1
FluoroAlien
LQ Newbie
 
Registered: Feb 2004
Distribution: Mandrake 9.2 & Sun JDS
Posts: 4

Rep: Reputation: 0
Simple scripting question - running a command for a specified time


Like I said, i'm sure it's actually a fairly easy thing to do, and i'm equally certain i'm being quite slow and missing something obvious, can someone explain how I can, in a bash script, get a command to run for a specified length of time before being killed?

Cheers
 
Old 03-03-2004, 03:11 PM   #2
cjcuk
Member
 
Registered: Dec 2003
Distribution: Openwall, ~LFS
Posts: 128

Rep: Reputation: 15
A simple method with shell scripting would be to run the sleep command and then predictably signal the process via the kill command.
 
Old 03-03-2004, 08:04 PM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
program &; sleep 1h; killall program
 
Old 03-04-2004, 01:05 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Try using timelimit - to run "script.sh" for max of 60 seconds:
timelimit 60 script.sh
 
Old 03-04-2004, 02:57 PM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
it took me almost 15 minutes to find timelimit and get it working.
it's part of netpipes which i don't have installed.
that took me a few minutes. then i couldn't
get it to compile. then i copied it out of a copy of knoppix.
it looks less awkward than sleep.
 
Old 03-04-2004, 03:05 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
heh, comes as standard on Slack 9.1
 
Old 03-04-2004, 03:33 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Or 8.1, for that matter :D


Cheers,
Tink
 
Old 03-05-2004, 05:33 AM   #8
FluoroAlien
LQ Newbie
 
Registered: Feb 2004
Distribution: Mandrake 9.2 & Sun JDS
Posts: 4

Original Poster
Rep: Reputation: 0
Cheers for all the suggestions folks, i've got it working with the sleep command (I was right, there was something obvious I was missing, cheers for staying polite when pointing it out ).

It doesn't look like timelimit is installed on my system at the moment (Mandrake 9.2), but i'm gonna look into that as well as it does look pretty handy.
 
Old 03-06-2004, 12:33 AM   #9
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,831

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
program +ACY-; sleep 1h; killall program
I've used constructs like:
Code:
program +ACY-
BGPID=+ACQ-!
sleep +ACQ-AWHILE
kill -15 +ACQ-BGPID
and it works pretty well. (And it works on non-Linux systems that don't have killall.)
 
  


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
Very simple BASH scripting question clickster Linux - Newbie 6 11-23-2005 04:28 PM
Simple Shell Scripting Question hellomynameisphil Programming 2 08-27-2005 03:41 AM
Simple bash/awk/sed scripting question R00ts Programming 4 04-16-2005 02:55 AM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
simple scripting question wedgeworth Programming 6 02-04-2004 10:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:03 AM.

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
Open Source Consulting | Domain Registration