Hey everyone! I've written a couple of bash scripts for PostgreSQL operations and I'm looking for some feedback. One script, `logger_utils.sh`, contains functions for logging various types of messages with color support while the other, `postgres_utils.sh`, handles common database operations like creating, dropping databases and users, and dumping/restoring databases. This is the first time I've put together something this comprehensive, so I'm eager to hear any critiques or suggestions for improvement. Thanks for your help!
4 Answers
Just a heads-up, your scripts might have issues when run on a non-interactive server environment where there’s no ${HOME}/Desktop. It's better to allow scripts to adapt to the server setup. Also remember to implement better error handling to avoid crashes! Utilizing log levels could help keep things tidy in your logs.
About your color handling: If you're scripting for Unix-like systems, there's a better way to check for terminal colors. Directly setting color codes might mess up user preferences or terminal types. It's safer to use `tput` for color support. This way, you can ensure compatibility across different terminal emulators. Check out [this guide](https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x241.html) for more tips!
Make sure to format your code snippets properly for clarity. It makes a big difference when you're sharing scripts. A simple method is to use four spaces before each line of code and leave a blank line between code and text for better readability!
I like your setup! But when you get the current timestamp, consider simplifying it using `printf` instead of calling `date`. You can get the same format with `printf -v timestamp '%(%FT%T%z)T' -1`, which is a bit cleaner.

Oh, good point! I hadn't thought of that! Thanks for the tip!