Running a shell command for a specific period of time

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Lynn David Newton
Date:  
To: Main PLUG discussion list
Subject: Running a shell command for a specific period of time

e> I was wondering if anyone knew a way to allow a
e> shell command to run for a specific period of
e> time. ...


Lots of solutions. One simple one would be to put
something like this in a script and run it.

----------------------- doit.sh -----------------------
#!/bin/bash
nohup somecmd arguments &
pid=$!
sleep 86399
kill -9 $pid
------------------------- end -------------------------

Of course "somecmd arguments" is whatever it is you
want to run for the specified period of time.

There is no guarantee that the command will expire on
its own before the sleep timeout.

Technically the nohup is not needed, but it will save
output to nohup.out without having to specify it.
Saving $! as pid is also technically superfluous, but
not a bad idea in practice, because $! can change in
the course of a longer script.

--
Lynn David Newton
MontaVista Software, Inc.
2141 E. Broadway Road, Suite 108
Tempe, AZ 85282
Phone: 480-517-5047
Email:
---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss