h.b h.b - 4 months ago 15
Linux Question

Error out to custom log file

I have a command that I run:

*command* |awk '!/""/{ORS=(/},/?RS:""); gsub(/[[:blank:]]+/,""); sub(/}$/,"},\n"); print}' | sed 's/"//g' | sed 's/{//g' | sed 's/}//g' > xxx_status.log

The result is in JSON pretty format that I need to modify for logging purposes. The command works well and the format is the way I need it. My problem is that if I run it and there's an error, it does not get logged in the log file I specified.

The following is an example of the error I can get that I would need logged:

[ERROR] There was an error executing your request:
[ERROR] Timed out waiting for response from component. Possible Reasons: 1) Invalid instance id provided. 2) System may not be configured properly. Make sure all system components are properly installed and running. 3) Insufficient timeout value. Try increasing the timeout value (--timeout ) and rerunning the command. [Details: None]

I tried adding 2>&1 at the end of my command line but it doesn't work. Log file is empty.

Can anyone help?


Error can be redirected to a file using below syntax:

command 2> errorFile.txt