Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

need bash command timeout help

187 views
Skip to first unread message

Todd

unread,
Feb 20, 2011, 8:12:57 PM2/20/11
to
Hi All,

I have a bash script with the following command in it.

Error="`su $DefaultUser -c "/usr/bin/VBoxManage \
--nologo guestcontrol execute "$VM_Name" \
'C:\Windows\system32\shutdown.exe' \
--arguments '/f /t 5 /s /d p:2:3' \
--username $WinAdminUser \
--password $WinAdminPassword \
--wait-for stdout" | \
grep ERROR`"

Problem, VBoxManage occasionally never completes and
the command hangs. The rest of the script will not
complete. And that creates a big problem.

If I put a "&" at the end of the grep command, it will still
have to wait for "Error=" to populate, so I am stuck.

Anyone know a way to run VBoxManage such that it will
time out if the command seizes?

Many thanks,
-T

Harald Meyer

unread,
Feb 20, 2011, 8:42:03 PM2/20/11
to
On 02/21/2011 02:12 AM, Todd wrote:

> Anyone know a way to run VBoxManage such that it will
> time out if the command seizes?

Maybe I didn't fully understand your problem, but are you aware
that there is a "timeout" utility? (in GNU coreutils)

Todd

unread,
Feb 20, 2011, 9:07:50 PM2/20/11
to
On 02/20/2011 05:42 PM, Harald Meyer wrote:
> On 02/21/2011 02:12 AM, Todd wrote:
>
>> Anyone know a way to run VBoxManage such that it will
>> time out if the command seizes?
>
> Maybe I didn't fully understand your problem,

If I execute an external command from a bash script, and
the command hangs, I want a way to force a timeout so my
script can continue.

> but are you aware
> that there is a "timeout" utility? (in GNU coreutils)

No I did not know. I am interested.

I have "coreutils":
# rpm -qa \*coreutils\*
coreutils-5.97-23.el5_4.2

But not "timeout"
$ timeout --help
bash: timeout: command not found

But I do have:
/usr/share/doc/bash-3.2/scripts/timeout
Is this the one your are talking about? Sure seems
like it.

Many thanks,
-T

Todd

unread,
Feb 20, 2011, 9:12:00 PM2/20/11
to
On 02/20/2011 06:07 PM, Todd wrote:

> But I do have:
> /usr/share/doc/bash-3.2/scripts/timeout
> Is this the one your are talking about? Sure seems
> like it.
>
> Many thanks,

timeout -KILL 5 sleep 20
Killed

This is what I am looking for. Thank you!

-T

Harald Meyer

unread,
Feb 20, 2011, 9:22:51 PM2/20/11
to
On 02/21/2011 03:07 AM, Todd wrote:
> On 02/20/2011 05:42 PM, Harald Meyer wrote:
>> but are you aware
>> that there is a "timeout" utility? (in GNU coreutils)
>
> No I did not know. I am interested.
>
> I have "coreutils":
> # rpm -qa \*coreutils\*
> coreutils-5.97-23.el5_4.2

It's 8.5-1 in current Ubuntu 10.10

> But not "timeout"
> $ timeout --help
> bash: timeout: command not found

| $ which timeout
| /usr/bin/timeout
| $ whatis timeout
| timeout (1) - run a command with a time limit
| $ dpkg -S /usr/bin/timeout
| coreutils: /usr/bin/timeout
| $ file /usr/bin/timeout
| /usr/bin/timeout: ELF 32-bit LSB executable, ...

> But I do have:
> /usr/share/doc/bash-3.2/scripts/timeout
> Is this the one your are talking about? Sure seems
> like it.

No, I don't know that script. I discovered "timeout" myself only recently,
don't know in which version it appeared.

Bill Marcum

unread,
Feb 20, 2011, 9:03:11 PM2/20/11
to
If your system has the killall command you could do this:
( sleep $Timeout; su $DefaultUser -c "killall VBoxManage" ) &

--
Science is to computer science as hydrodynamics is to plumbing.

Todd

unread,
Feb 20, 2011, 9:31:11 PM2/20/11
to


I am on old-out-of-date (Cent OS 5.5). CentOS 6.0 is due out any
day now, so maybe ...

The script seems to work fine.

Many thanks,
-T

/usr/share/doc/bash-3.2/scripts/timeout:

#Newsgroups: comp.unix.admin,comp.unix.solaris,comp.unix.shell
#From: g...@root.co.uk (Geoff Clare)
#Subject: Re: timeout -t <sec> <unix command> (Re: How to give rsh a #
shorter timeout?)
#Message-ID: <EoBxr...@root.co.uk>
#Date: Fri, 13 Feb 1998 18:23:52 GMT

#
# Conversion to bash v2 syntax done by Chet Ramey <ch...@po.cwru.edu
# UNTESTED
#

prog=${0##*/}
usage="usage: $prog [-signal] [timeout] [:interval] [+delay] \
[--] <command>"

SIG=-TERM # default signal sent to the process when the timer expires
timeout=60 # default timeout
interval=15 # default interval between checks if the process is
still alive
delay=2 # default delay between posting the given signal and
# destroying the process (kill -KILL)

while :
do
case $1 in
--) shift; break ;;
-*) SIG=$1 ;;
[0-9]*) timeout=$1 ;;
:*) EXPR='..\(.*\)' ; interval=`expr x"$1" : "$EXPR"` ;;
+*) EXPR='..\(.*\)' ; delay=`expr x"$1" : "$EXPR"` ;;
*) break ;;
esac
shift
done

case $# in
0) echo "$prog: $usage" >&2 ; exit 2 ;;
esac

(
for t in $timeout $delay
do
while (( $t > $interval ))
do
sleep $interval
kill -0 $$ || exit
t=$(( $t - $interval ))
done
sleep $t
kill $SIG $$ && kill -0 $$ || exit
SIG=-KILL
done
) 2> /dev/null &

exec "$@"


Todd

unread,
Feb 20, 2011, 11:20:15 PM2/20/11
to
On 02/20/2011 06:22 PM, Harald Meyer wrote:
>>> but are you aware
>>> >> that there is a "timeout" utility? (in GNU coreutils)
>> >
>> > No I did not know. I am interested.
>> >
>> > I have "coreutils":
>> > # rpm -qa \*coreutils\*
>> > coreutils-5.97-23.el5_4.2
> It's 8.5-1 in current Ubuntu 10.10
>
>> > But not "timeout"
>> > $ timeout --help
>> > bash: timeout: command not found
> | $ which timeout
> | /usr/bin/timeout
> | $ whatis timeout
> | timeout (1) - run a command with a time limit
> | $ dpkg -S /usr/bin/timeout
> | coreutils: /usr/bin/timeout
> | $ file /usr/bin/timeout
> | /usr/bin/timeout: ELF 32-bit LSB executable, ...
>
>> > But I do have:
>> > /usr/share/doc/bash-3.2/scripts/timeout
>> > Is this the one your are talking about? Sure seems
>> > like it.

Just added a call to the script version in my script.
Works perfectly. Thanks for pointing me in the
right direction!

-T

Lawrence D'Oliveiro

unread,
Feb 22, 2011, 10:53:24 PM2/22/11
to
In message <ijsftc$jqn$1...@news.eternal-september.org>, Harald Meyer wrote:

> ... but are you aware that there is a "timeout" utility? (in GNU
> coreutils)

LSNED! :)

Todd

unread,
Feb 23, 2011, 3:14:50 PM2/23/11
to

What?

Harald Meyer

unread,
Feb 23, 2011, 4:14:50 PM2/23/11
to
On 02/23/2011 09:14 PM, Todd wrote:
> On 02/22/2011 07:53 PM, Lawrence D'Oliveiro wrote:

>> LSNED! :)

> What?

Learn Something New Every Day :)

Todd

unread,
Feb 23, 2011, 5:02:00 PM2/23/11
to

Guess I did. "which lsned" didn't find anything. :'[

-T

Lawrence D'Oliveiro

unread,
Feb 23, 2011, 6:35:09 PM2/23/11
to

And to think I just made that up. :)

Todd

unread,
Feb 23, 2011, 11:13:29 PM2/23/11
to

It was the "ls" that got me. :-)

-T

$ ls /usr/bin/ls*
/usr/bin/lsattr /usr/bin/lsdiff /usr/bin/lshal /usr/bin/lss16toppm
/usr/bin/lsb_release /usr/bin/lsdvd /usr/bin/lspgpot /usr/bin/lsscsi

0 new messages