[TriLUG] Starting and stopping jobs with cron

Brian Henning lugmail at cheetah.dynip.com
Thu Dec 9 21:52:40 EST 2004


If it's the only process running with its particular command name (e.g. if
it were named myscript.sh, and was reliably the only instance of myscript.sh
running at the time), you can use killall to kill a process by command name
rather than pid, e.g.:

$ killall -SIGTERM myscript.sh

Of course, as its name implies, if there is more than one instance of
myscript.sh running, they will all be sent the specified signal.

Someone suggested using $$ for the PID, but I believe that is only within
the scope of that process (i.e. within the script itself), and possibly not
useful in this instance since you want to kill a process from another
process.

HTH,
~Brian


-----Original Message-----
From: trilug-bounces at trilug.org [mailto:trilug-bounces at trilug.org]On
Behalf Of Victor Snesarev
Sent: Thursday, December 09, 2004 7:33 PM
To: Triangle Linux Users Group discussion list
Subject: [TriLUG] Starting and stopping jobs with cron


Here's the situation... I start a process using cron, but I need to kill
that process one hour later using cron. There doesn't seem to be a
crontab option to run a command for a specified period of time. I
suppose I could set an environment variable at the start of the process
containing the process ID and an hour later use that environment
variable as an argument to "kill", but I do not know a way to retrieve
the process ID.

Would it be easy to parse "ps | grep <command_name>" or is there an
better way to do this?

Any suggestions?

TIA,
Victor
--
TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
TriLUG Organizational FAQ  : http://trilug.org/faq/
TriLUG Member Services FAQ : http://members.trilug.org/services_faq/
TriLUG PGP Keyring         : http://trilug.org/~chrish/trilug.asc




More information about the TriLUG mailing list