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
> 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)
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
> 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
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.
--
Science is to computer science as hydrodynamics is to plumbing.
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 "$@"
Just added a call to the script version in my script.
Works perfectly. Thanks for pointing me in the
right direction!
-T
> ... but are you aware that there is a "timeout" utility? (in GNU
> coreutils)
LSNED! :)
What?
>> LSNED! :)
> What?
Learn Something New Every Day :)
Guess I did. "which lsned" didn't find anything. :'[
-T
And to think I just made that up. :)
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