Here's the general command logging function I wrote:
function exec_cmd() {
{
echo "$(date '+%Y-%m-%d %H:%M:%S')" "$1"
$1
} >>./cmd.log
}
When I call this function with exec_cmd "modprobe -r toa || true"
, I got an error "modprobe: FATAL: Module || not found."
Running the same command without the wrapper exec_cmd
works as expected.
The whole script is running in strict mode. The ||
were included because only the error from this command can be ignored.