Unix Shell - scheduling tasks

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2007 > scheduling tasks





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author scheduling tasks
Ben

2007-05-24, 7:18 pm

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

DaveG

2007-05-24, 7:18 pm

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.
Ben

2007-05-24, 7:18 pm

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:
>
>
> 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.



DaveG

2007-05-24, 7:18 pm

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.
SiKing

2007-05-25, 7:17 am

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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com