LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-07-2002, 08:17 PM   #1
Brett-NZ
LQ Newbie
 
Registered: Dec 2002
Location: Gisborne, NZ
Distribution: Slackware 9.1
Posts: 7

Rep: Reputation: 0
Question Running a program for a specified time


Hello again.

Does anyone know a way to force a program to run for a specified time and then shut down - some kind of script wizardry perhaps?

The reason for this is that I'm connected to the 'net through an ADSL router, the port routes for which cause an unusual problem when I need net access. I have to repeatedly run lynx and shut it down (Ctrl-C) - for about 44 iterations. I can still ping my ISP's DNS', but anything beyond that seems to be unavailable until I do my little routine.

Any help would be appreciated.
 
Old 12-07-2002, 08:42 PM   #2
ubien
Member
 
Registered: Oct 2002
Distribution: RH 8.0 and fluxbox
Posts: 122

Rep: Reputation: 15
you could run the program and then use either cron or at to "killall program name". Using at would be something like:
at 1:00pm
killall program_name
ctrl-d
 
Old 12-08-2002, 12:46 AM   #3
neo77777
LQ Addict
 
Registered: Dec 2001
Location: Brooklyn, NY
Distribution: *NIX
Posts: 3,704

Rep: Reputation: 56
Well, I would rather think of cron, so you don't have to type it every time, the entry in crontab would look like:
Code:
20 2 * * * /usr/bin/run-parts /etc/cron.daily 1> /dev/null
To run it daily at 2:20am
then you put your script that should run in /etc/cron.daily
The script is two liner or more, but the first line should be
#!/path/to/shell/or/interpreter
like
#!/bin/sh
which invokes commands in Bourne Shell context.
Code:
#!/bin/sh
/comand/to/execute
The command to edit/see scheduled jobs by cron is
crontab -e

Last edited by neo77777; 12-08-2002 at 12:48 AM.
 
Old 12-08-2002, 06:43 PM   #4
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,185

Rep: Reputation: 52
programname & ; sleep 20m; killall programname
 
Old 12-08-2002, 06:48 PM   #5
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,185

Rep: Reputation: 52
how about this


integer x=1
while ((x <=44))
do
programname &
sleep 10s
killall programname
((x = x + 1))
fi
 
  


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
Time is running out for me. ccalvin12 Linux - Software 1 08-05-2005 08:18 AM
time functions in a c program mbacke Programming 3 04-18-2005 03:42 PM
Running a program for a specific period of time CaptainHowdy Linux - Software 2 08-22-2004 08:02 PM
Running 2 OS at the same time NeoSpawn Linux - General 18 06-17-2004 06:42 PM
how to write a program can have 2 threads running at the same time?? man9 Programming 3 10-07-2000 02:43 PM


All times are GMT -5. The time now is 04:27 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