I am trying to use a shell program that I have been left to get running. The program starts as shown below.
#!/usr/bin/env bash
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>$1/logs/$(date '+%Y%m%d_%H%M%S')_start.log 2>&1
The program is a .sh with the input ($1) being the output folder such that it is looking in /output/logs..., the program fails on the exec line, this is my first time using bash and shell scripting but I think this line essentially redirects all the standard outputs to the log file?
The program error say
cannot create /output/logs/20230203_12345_start.log: directory non-existent
should this line also create the log file if it is non existent? I don't see how you could create the .log file first as otherwise you would get the seconds part of the title wrong?
out="$1/logs/$(date '+%Y%m%d_%H%M%S')_start.log"; >"$out"; exec 1>"$out" 2>&1