Similar to How to check how long a process has been running?, I am trying to get the elapsed time for a process in seconds in an embedded Linux system using BusyBox and sh
(not bash
). The difference is that I would like it in pure seconds, not mm:ss format.
I can parse it out of the result of ps
but am unable to get expr
to convert from mm:ss to seconds. Using set -vx
to help with debugging I can see the valid expr
command but it fails with a syntax error. Copying and pasting it works fine.
After running this for added diagnostics:
root@embedded:~# set -vx
I enter:
root@embedded:~# $(/opt/bin/busybox ps -o pid,etime,time | grep 1156 | sed "s/ *[0-9]\+ \+\([0-9]\+\):\([0-9]\+\) .*/\/opt\/bin\/busybox expr \1 \\\* 60 + \2/")
And get this response:
$(/opt/bin/busybox ps -o pid,etime,time | grep 1156 | sed "s/ *[0-9]\+ \+\([0-9]\+\):\([0-9]\+\) .*/\/opt\/bin\/busybox expr \1 \\\* 60 + \2/")
+ /opt/bin/busybox ps -o pid,etime,time
+ grep 1156
+ sed s/ *[0-9]\+ \+\([0-9]\+\):\([0-9]\+\) .*/\/opt\/bin\/busybox expr \1 \\* 60 + \2/
+ /opt/bin/busybox expr 2 \* 60 + 03
expr: syntax error
root@embedded:~#
I have additionally tried multiple layers of \
escapes and also ''
.
What do I need to do to get the escaping of the *
to pass through to the expr
command line?
ps
because the system version didn't include support for-o
. In the second case I was just trying it out to see if there was a difference between the two binaries forexpr
as well. – altendky Jun 08 '15 at 16:22