LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Running a program for a specified time (https://www.linuxquestions.org/questions/linux-newbie-8/running-a-program-for-a-specified-time-37609/)

Brett-NZ 12-07-2002 07:17 PM

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.

ubien 12-07-2002 07:42 PM

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

neo77777 12-07-2002 11:46 PM

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

whansard 12-08-2002 05:43 PM

programname & ; sleep 20m; killall programname

whansard 12-08-2002 05:48 PM

how about this


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


All times are GMT -5. The time now is 12:59 PM.