PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > scheduling tasks
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

scheduling tasks

Réponse
 
LinkBack Outils de la discussion
Vieux 24/05/2007, 23h12   #1
Ben
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut scheduling tasks

How to schedule tasks on UNIX/Linux?

I don't think cron is neccessary, since I just wanna do something one-
off, like start program_a from 3pm, stop at 4pm, and resume at 5pm,
etc

Regards,
Ben

  Réponse avec citation
Vieux 24/05/2007, 23h39   #2
DaveG
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: scheduling tasks

On Thu, 24 May 2007 15:12:54 -0700, Ben wrote:

> How to schedule tasks on UNIX/Linux?
>
> I don't think cron is neccessary, since I just wanna do something one-
> off, like start program_a from 3pm, stop at 4pm, and resume at 5pm, etc


man at :-)
(plus some creative scripting to stop/kill at the "end" time)

--
DaveG
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.
  Réponse avec citation
Vieux 25/05/2007, 00h29   #3
Ben
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: scheduling tasks

Can you give me some ideas on stopping/killing a job, e.g. wget?


On May 24, 11:39 pm, DaveG <nos...@nospam.net> wrote:
> On Thu, 24 May 2007 15:12:54 -0700, Ben wrote:
> > How to schedule tasks on UNIX/Linux?

>
> > I don't think cron is neccessary, since I just wanna do something one-
> > off, like start program_a from 3pm, stop at 4pm, and resume at 5pm, etc

>
> man at :-)
> (plus some creative scripting to stop/kill at the "end" time)
>
> --
> DaveG
> To the optimist, the glass is half full.
> To the pessimist, the glass is half empty.
> To the engineer, the glass is twice as big as it needs to be.



  Réponse avec citation
Vieux 25/05/2007, 01h01   #4
DaveG
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: scheduling tasks

On Thu, 24 May 2007 16:29:10 -0700, Ben wrote:

> Can you give me some ideas on stopping/killing a job, e.g. wget?
>


It depends on what you mean by stopping/killing "wget". Is that a run by
a script in a loop?

The only time I've needed to do it under script control is for a timelapse
image grab.


stoptime=22
while [ "`date "+%H"`" != ${stoptime} ] ; do
# rest of script goes here
done

I run it from cron everyday at 4am and it stops itself at 22:00hrs

Using at to start it as a "one off" timed job would work too.


Another way would be to get the process ID at a specified time and send a
kill signal.
--
DaveG
To the optimist, the glass is half full.
To the pessimist, the glass is half empty.
To the engineer, the glass is twice as big as it needs to be.
  Réponse avec citation
Vieux 25/05/2007, 08h27   #5
SiKing
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: scheduling tasks

Ben wrote:
> Can you give me some ideas on stopping/killing a job, e.g. wget?


Hi Ben,

I work in SW test, and we often need to monitor runtime of stuff, and kill it if
it runs (hangs?) too long. I am attaching a script that we use just for this.
Perhaps with a few modifications, you could adopt it for your needs.

Actually, I would be interested in getting some critique from the group on the
script itself.

HTH.



#!/usr/bin/env bash
#########1#########2#########3#########4#########5 #########6#########7#########8
#
# Will monitor the runtime of a command and terminate it if it runs too long.
#
# Usage:
# tc_monitor "<command> [arguments]" <time-to-live> [poll-frequency]
#
# Arguments:
# $1 = command to run (must be quoted if multiple words)
# $2 = seconds to let $1 live, if 0 will let the command live "forever"
# $3 = poll frequency, optional, defaults to 2 seconds
#
# Exit status:
# 1 - if incorrect number of arguments is supplied
# same as <command> - if <command> completes before $2
# 15 - if <command> must be terminated
# 3 - if <command> must be quit
# 9 - if <command> must be killed
#
#########1#########2#########3#########4#########5 #########6#########7#########8


# Simple sanity test first.
if [ $# -lt 2 ]
then
exit 1
fi


_self=`basename $0` # name of this executable


# If time to live is zero, then "become" the command and let it end naturally.
if [ $2 -eq 0 ]
then
eval exec "$1"
fi


# Run the command, remember to preserve its exit status ... if it gets that far.
(eval "$1"; printf $? > /tmp/${_self}.$$) &
while [ -d "/proc/$!" -a $SECONDS -lt $2 ]
# The above says: while the background command lives (the -d thing) and (the -a)
# time counter is less than time to live argument passed (the -lt thing) ...
do
sleep ${3:-2}
done

# If the command comleted, then generate the same exist staus as it did.
if [ ! -d "/proc/$!" ]
then
exit $(cat /tmp/${_self}.$$)
fi


# TERMinate the command, if it is still running.
if [ -d "/proc/$!" ]
then
kill -TERM $!
# we need to know if this worked
if [ $? -eq 0 ]
then
exit $(kill -l TERM)
fi
fi

# QUIT the command, if it is still running.
# This normaly causes the running command to dump a core file!
if [ -d "/proc/$!" ]
then
kill -QUIT $!
if [ $? -eq 0 ]
then
exit $(kill -l QUIT)
fi
fi

# KILL the command, if is is still running.
if [ -d "/proc/$!" ]
then
kill -KILL $!
if [ $? -eq 0 ]
then
exit $(kill -l KILL)
fi
fi
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h12.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15691 seconds with 13 queries