I want to use mod_substitute
or mod_ext_filter
to replace a string with the current timestamp in miliseconds.
I tried so far, but it's not working.
Substitute "1s/myString/&$(date +"%T.%3N")/"
ExtFilterDefine testfilter mode=output intype=text/html cmd=/bin/echo "$(sed -E "1s/myString/&$(date +"%T.%3N")/")"
Does someone has the idea to get this running? I was also thinking about, to combine it with ssi, but also not working.
From reading the
mod_substitute
documentation, I cannot find a single reference as to why you would think it would work with executing an external process (or forking a shell, or anything of that sort). So I would not consider this route to be a viable one.mod_ext_filter
, on the other hand, seems adapted to what you wish to do. However, to quote its documentation:So, if I were you, I'd consider using a dynamic language such as PHP (which was initially written for this very use case), or eventually writing a very small C program to do what you want, as it would end up much faster, and it isn't too hard.
Now, if you want to persist with your idea, don't use
/bin/echo
. The substitution you wrote in"$(sed -E "1s/myString/&$(date +"%T.%3N")/")"
requires a shell, and/bin/echo
will not spawn one. Therefore, you need to either write a script (solution I would recommend), or at least call/bin/sh
(or/bin/bash
if you're so inclined) with the proper arguments:-c 'var="$(date +"%T.%3N")"; sed -E "1s/myString/&$var/"'
.It's really hacky, and I maintain a PHP script or a C program would be simpler in the long run, but to each their own.